Drive's current directory path enumeration

File system entries obtained using a path argument in the shape of a "drive's current directory", for example, C:, were incorrectly formed by combining directory path + separator + entry name. To return the correct path for the entries, the separator is no longer added with such paths.

Previous behavior

Previously, a separator character was added such that the enumerated file system entries appeared to be in the drive's root.

string pathToEnumerate = "C:";

Console.WriteLine($"Full path of \"{pathToEnumerate}\" is {Path.GetFullPath(pathToEnumerate)}.");
Path.GetFullPath(pathToEnumerate);

Console.WriteLine($"Enumerating files and folders in \"{pathToEnumerate}\".");
foreach (string entry in Directory.GetFileSystemEntries(pathToEnumerate))
{
    Console.WriteLine(entry);
}

The output from running this code snippet was as follows.

Full path of "C:" is C:\Users\myalias\consoleapps\Program

Enumerating files and folders in "C:".
C:\Program.csproj
C:\Program.sln
C:\bin
C:\obj
C:\Program.cs

New behavior

Running the same code snippet in .NET 9 and later versions produces output without a separator character in each path.

Full path of "C:" is C:\Users\myalias\consoleapps\Program.

Enumerating files and folders in "C:".
C:Program.csproj
C:Program.sln
C:bin
C:obj
C:Program.cs

Version introduced

.NET 8

Type of breaking change

This change is a behavioral change.

Reason for change

Users reported that the previous behavior was incorrect. It was also a regression from .NET Framework.

If you're a Windows user who relies on enumeration of paths like C:, you should re-evaluate your application's I/O operations. This is an unusual scenario that's unlikely to be used in production. Most users who want to enumerate the current directory use Environment.CurrentDirectory instead.

Affected APIs