Does Directory.GetDirectories(path) return full paths or just names?

≡放荡痞女 提交于 2019-12-12 11:42:16

问题


In the MSDN documentation, it says it returns just directory names("Return Value Type: ... An array of type String containing the names of subdirectories in path."), however in their example code, they recurse without concatenating them, so does that mean they return the full paths?

i.e. their example code:

public static void ProcessDirectory(string targetDirectory) 
    {
        // Process the list of files found in the directory.
        string [] fileEntries = Directory.GetFiles(targetDirectory);
        foreach(string fileName in fileEntries)
            ProcessFile(fileName);

    // Recurse into subdirectories of this directory.
    string [] subdirectoryEntries = Directory.GetDirectories(targetDirectory);
    foreach(string subdirectory in subdirectoryEntries)
        ProcessDirectory(subdirectory);
}

would not work if the GetDirectories method only returned directory names!


回答1:


As specified in the function's MSDN page:

The names returned by this method are prefixed with the directory information provided in path [ed: the parameter to the function].




回答2:


It returns full paths. You can verify with PowerShell:

[IO.Directory]::GetDirectories('C:\')


来源:https://stackoverflow.com/questions/1461652/does-directory-getdirectoriespath-return-full-paths-or-just-names

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!