each_entry() public

Iterates over the entries (files and subdirectories) in the directory, yielding a Pathname object for each entry.

Show source
Register or log in to add new notes.
December 23, 2008
0 thanks

Entries are not standalone!

The entry Pathnames consist solely of leaf filenames, so they’re not directly useable in filesystem operations like “open” or “directory?”. To create a useable Pathname, append the entry onto the directory you’re iterating over.

Also keep in mind that the iteration includes the magic entries “.” and “..”, which you probably want to skip. (Is this true on Windows too?)

The #children method doesn’t have either of these issues, although it’s slightly less efficient since it creates an Array of Pathnames up-front instead of yielding one at a time.