method

each_entry

v2_6_3 - Show latest stable - Class: Pathname
each_entry()
public

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

1Note

Entries are not standalone!

snej ยท Dec 23, 2008

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.