Search code examples
.netfilesystemsdirectory-structure

Oddity with System.IO.Directory.GetDirectories


Just something I noticed today when doing directory searches that might trip some people up.

I found on my Windows XP machine that

System.IO.Directory.GetDirectories("C:\") gave me 17 folders

System.IO.Directory.GetDirectories("C:") gave me 17 folders

System.IO.Directory.GetDirectories("D:\") gave me 12 folders

System.IO.Directory.GetDirectories("D:") gave me 0 folders

I was trying to figure out why my search was missing my D drive.


Solution

  • My guess is that GetDirectories("D:") gives you the list of directories within the current directory of your D drive, while GetDirectories("D:\") gives you the list of directories in the root of your D drive.

    If your D drive's root has 12 directories and the current directory is on your D drive and has no directories in it, those are the results you should expect.