Skip to content

FileManager.enumerator(at:) stops iterating upon seeing path that exceeds MAX_PATH on Windows #5135

Open
@ahoppen

Description

@ahoppen

Run the following to create a file at a path that exceeds MAXPATH

cd $HOME\Desktop
mkdir directoryTest
cd directoryTest
echo a > a.txt
echo a > z.txt
mkdir eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
subst Z: .\eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee\
Z:
echo a > eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee.txt

Now run

import Foundation

let enumerator = FileManager.default.enumerator(at: URL(fileURLWithPath: #"C:\Users\alex\Desktop\directoryTest"#), includingPropertiesForKeys: nil)
while let url = enumerator?.nextObject() as? URL {
  print(url)
}

Notice how it outputs

file:///C:/Users/alex/Desktop/directoryTest/z.txt
file:///C:/Users/alex/Desktop/directoryTest/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee/

Directory iteration stops upon reaching the eeeee…txt file that exceeds MAX_PATH and a.txt is never printed. I would expect directory iteration to either

  • Skip the files that exceed the maximum path length but continue iteration afterwards or
  • Return all files even those that exceed the maximum path length

but not to stop iteration upon reaching the first file that exceeds the maximum path length altogether.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions