If your platform supports the concept of inode number , you can save one number for each directory by specifying the largest inode number you visited for that particular directory. If you access inodes in numerical order, tracking one record will be good enough to find out where the next record is.
This is a small gain, since you still need to maintain an inode number for each individual directory in the system, but you will not need to worry about the contents of the directories.
Of course, bearing in mind that any bypass mechanism is subject to terrible conditions of the race, you will need to have some level of confidence that the file system is at rest or your code is resistant to directories / files that are deleted, created, moved, etc., while your code is already running.
source share