A quick test using readdir in scalar context did find a file created after the opendir command..if it's name comes after the current file being processed in alphabetical order. And even that wasn't consistent; could be a fault of the slapdash test methodology. But based on this, I would not count on it finding newly created files.
| [reply] |
I would expect the outcomes to be unpredictable. The directory-scan is, by definition, passing through a highly volatile data structure without the benefit of locks. The data structure being traversed, in most file systems, is not simply “a list,” but a tree of some kind. If the directory is updated while a particular scan is going on, the results of that scan might be quite unpredictable ... with omitted entries, possible duplicates, and so on.
A program which makes any assumptions at all about the outcome of this scenario will, eventually, produce incorrect results ... probably without realizing that it has done so.
| |