JohnSundell / Files

A nicer way to handle files & folders in Swift
MIT License
2.53k stars 182 forks source link

"\" characters confuse "Folder.subfolders" #130

Closed gavineadie closed 2 years ago

gavineadie commented 2 years ago

This took a long time to pin down!

The following directory will confuse baseDirectory.subfolders.includingHidden.count() because the embedded backslash characters indicate, falsely, that there are directories present. It is quite difficult to create files like that .. in this case they were created by a legacy version of Entourage. Another way they could be created (it may also be a legacy mechanism) is by pasting an image into a Finder icon via "Get Info.." which creates a file called Icon\015 in the directory.

    /baseDirectory
    ├──  About This Menu...
    ├── Create Event from Message\cE
    ├── Create Note from Message\cN
    ├── Create Task from Message\cT
    ├── Insert Text File...
    └── Save Selection...
gavineadie commented 2 years ago

My diagnosis seems to be wrong .. further exploration reveals more complexity.

Removing the offensive files from the above tree doesn't solve the problem, copying the baseDirectory (after removing those files) propagates the problem, but creating a new baseDirectory and creating contained files from scratch doesn't suffer. For now, I'm concluding those \ files make a permanent corruption to that part of the file structure they were contained in.

The specific issue, which Finder and Terminal don't reveal, is that the enumeration of the folders in baseDirectory contains baseDirectory itself and subFolders goes terminally recursive. The usage:

baseFolder.subfolders.recursive.names()

doesn't ever return.

gavineadie commented 2 years ago

.. but this problem will 'never' happen because files containing a \ in their names can't be created in the modern era, so I'm closing this and erasing it from my recollection of hours of frustration!