|
Syntax:
public static string GetDirectoryName(string path)
Example:
using System; using System.IO;
public class CGetDir{
public static void Main() {
string fileName = @"C:\mydir\myfile.ext";
string path = @"C:\mydir\";
string rootPath = @"C:\";
string directoryName;
directoryName = Path.GetDirectoryName(fileName);
// directoryName will conatin 'C:\mydir'
directoryName = Path.GetDirectoryName(path);
// directoryName will conatin 'C:\mydir'
directoryName = Path.GetDirectoryName(rootPath);
// directoryName will conatin '' Note:If the path consists of a root directory, such as "c:\", null is return
}
}
|