tags:

views:

588

answers:

1

When calling DirectoryInfo.GetDirectories(".") on an instance of a DirectoryInfo class which points to a valid folder (excluding drive roots), the result is a DirectoryInfo array whose first (and only) element points to a invalid directory named the same as itself, below itself.

For example:

static void Main(string[] args)
{
    DirectoryInfo di = new DirectoryInfo("c:\\temp");
    DirectoryInfo[] dis = di.GetDirectories(".");
    Console.WriteLine(dis[0].FullName);
}

Prints out a non-existent directory:

c:\temp\temp

I understand that in Windows, a "." refers to the current directory. That might be acceptable to me if the method returned "c:\temp", but returning a fake subdirectory with the same name seems like absolutely the wrong behavior.

I should be able to assert that any DirectoryInfo object returned from this function actually exists.... right?!

I decompiled the class using .NET Reflector, but it leads to this method

internal static string[] InternalGetFileDirectoryNames(string path, string userPathOriginal, string searchPattern, bool includeFiles, bool includeDirs, SearchOption searchOption)"

Which is a BEAST and I don't feel like walking through the logic in my head. It's clearly a bug IMHO.

FYI - a "*" works as expected, before someone asks.

+7  A: 

I can confirm what you say, and can't see any rational explanation for it, so I'm voting BUG.

I think so as well, I submitted it to Microsoft

James Curran