Description
File system entries obtained using a path argument in the shape of a "drive's current directory" e.g. C: were incorrectly formed by combining directory path + separator + entry name. We now avoid adding the separator with such paths to return the correct path for the entries.
Version
.NET 8 GA
Previous behavior
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);
}
// Output
/*
Full path of "C:" is C:\Users\dacantu\consoleapps\Program
Enumerating files and folders in "C:".
C:\Program.csproj
C:\Program.sln
C:\bin
C:\obj
C:\Program.cs
*/
Notice the enumerated entries are shown as if they were in the drive's root.
New behavior
Using above code snippet, the output for .NET 9 is the following.
Full path of "C:" is C:\Users\dacantu\consoleapps\Program.
Enumerating files and folders in "C:".
C:Program.csproj
C:Program.sln
C:bin
C:obj
C:Program.cs
Type of breaking change
Reason for change
Users were reporting that this behavior was not correct, and it was also a regression from .NET Framework.
Recommended action
Windows users relying on enumeration of paths like C: should re-evaluate their application's IO operations. IMO, this is an unusual scenario unlikely to be used in production. Most users wanting to enumerate the current directory would use Environment.CurrentDirectory instead.
Feature area
Core .NET libraries
Affected APIs
System.IO.Directory.EnumerateFiles*
System.IO.Directory.EnumerateDirectories*
System.IO.Directory.EnumerateFileSystemEntries*
System.IO.Directory.GetFiles*
System.IO.Directory.GetDirectories*
System.IO.Directory.GetFileSystemEntries*
System.IO.DirectoryInfo.EnumerateFiles*
System.IO.DirectoryInfo.EnumerateDirectories*
System.IO.DirectoryInfo.EnumerateFileSystemEntries*
System.IO.DirectoryInfo.GetFiles*
System.IO.DirectoryInfo.GetDirectories*
System.IO.DirectoryInfo.GetFileSystemEntries*
System.IO.Enumeration.FileSystemEnumerable<TResult>.ctor(string, FileSystemEnumerable<TResult>.FindTransform transform, EnumerationOptions?)
Associated WorkItem - 206388
Description
File system entries obtained using a path argument in the shape of a "drive's current directory" e.g.
C:were incorrectly formed by combining directory path + separator + entry name. We now avoid adding the separator with such paths to return the correct path for the entries.Version
.NET 8 GA
Previous behavior
Notice the enumerated entries are shown as if they were in the drive's root.
New behavior
Using above code snippet, the output for .NET 9 is the following.
Type of breaking change
Reason for change
Users were reporting that this behavior was not correct, and it was also a regression from .NET Framework.
Recommended action
Windows users relying on enumeration of paths like
C:should re-evaluate their application's IO operations. IMO, this is an unusual scenario unlikely to be used in production. Most users wanting to enumerate the current directory would useEnvironment.CurrentDirectoryinstead.Feature area
Core .NET libraries
Affected APIs
Associated WorkItem - 206388