GetPathRoot的用途是用來獲取指定路徑的根目錄信息。例如C語言中:string path = @"\mydir\";string fileName = "myfile.ext";string fullPath = @"C:\mydir\myfile.ext";string pathRoot。
用途,c#舉例,
用途
獲取指定路徑的根目錄信息。
c#舉例
string path = @"\mydir\";
string fileName = "myfile.ext";
string fullPath = @"C:\mydir\myfile.ext";
string pathRoot;
pathRoot = Path.GetPathRoot(path);
Console.WriteLine("GetPathRoot('{0}') returns '{1}'", path, pathRoot);
pathRoot = Path.GetPathRoot(fileName);
Console.WriteLine("GetPathRoot('{0}') returns '{1}'", fileName, pathRoot);
pathRoot = Path.GetPathRoot(fullPath);
Console.WriteLine("GetPathRoot('{0}') returns '{1}'", fullPath, pathRoot);
// This code produces output similar to the following:
//
// GetPathRoot('\mydir\') returns '\'
// GetPathRoot('myfile.ext') returns ''
// GetPathRoot('C:\mydir\myfile.ext') returns 'C:\'