How do I get the directory from a file's full path?
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”.
If you’ve definitely got an absolute path, use
If you might only get a relative name, use
FileInfo are both found in the namespace
Answered By – Jon Skeet