Maybe a clever trick would be to make sure all hidden variants can be masked on the same bit, which forces assigning specific values to these enums. What mask size is appropriate to assign presuming the hidden bit is the msb? Would these changes be accepted in the standard library breaking previous code? Any more new flags these procs should take care of?
What I've been wanting to do for a while is write an updated walkDirRec which gets all files, but returns the entire file's information. The signature could be something like:
iterator walkPath(path: string, follow, filter: set[TPathComponent]): FileInfo
## Walks the directory `path` for files, returning files who are of the type specified by `filter` and
## following files of the type specified by `follow`. Path components in `follow` that cannot be followed
## (like pcFile and pcLinkToFile) are ignored.
You could also take a callback based approach to file filtering:
type fileCallback = proc (info:FileInfo): tuple[follow, filter: bool]
proc walkPath(path: string, callback: fileCallback)
## Walks the directory `path` for files, calling `callback` with each file found. The tuple the callback returns determines
## whether the procedure continues following a path or continues at all.
The procedures above allows recursive and non-recursive behavior, following symlinks, file filtering etc. It doesn't take into account hidden/non-hidden files, but this could be added. Actually, whether a file is hidden or not is found out by getFileInfo, but the information isn't exposed, since on Windows being 'hidden' is an attribute, and on Unix-like systems it's a tradition brought about by a naming scheme.
Any suggestions/improvements?
Any suggestions/improvements?
Sets are cooler than callbacks. ;-)