Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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!

like image 539
Ed James Avatar asked Dec 14 '22 02:12

Ed James


2 Answers

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].

like image 193
Traveling Tech Guy Avatar answered Dec 15 '22 14:12

Traveling Tech Guy


It returns full paths. You can verify with PowerShell:

[IO.Directory]::GetDirectories('C:\')
like image 45
dahlbyk Avatar answered Dec 15 '22 14:12

dahlbyk