Alex Rivera | Logout

How do I get the directory from a file's full path?

Asked 2009-03-23T17:49:13.673
680

What is the simplest way to get the directory that a file is in? I'm using this to set a working directory.

string filename = @"C:\MyDirectory\MyFile.bat";

In this example, I should get "C:\MyDirectory".

Edit
Report

1 Answer

11

You can use Path.GetDirectoryName and just pass in the filename.

MSDN Link

answered 2009-03-23T17:52:45.863

Your Answer