How do I get the directory from a file's full path?
If you've definitely got an absolute path, use Path.GetDirectoryName(path)
.
If you might only get a relative name, use new FileInfo(path).Directory.FullName
.
Note that Path
and FileInfo
are both found in the namespace System.IO
.
System.IO.Path.GetDirectoryName(filename)
Path.GetDirectoryName(filename);