Tuesday, June 26, 2012

Ruby Dir.glob to provides some of the python os.walk functionality

The ruby Dir.glob command is pretty nice. It provides some of what os.walk provides for python and is a reasonable choice for working with files and directories. Double * gets you recursion. Quick and dirty way to list user home directories and user-level global environment file:
Dir.glob("/Users/**/.MacOSX/environment")
More comprehensive is to use dscl, but it is more work, first get a list of users:
dscl . -list /Users
Then iterate over each of those:
dscl . -read /Users/myuser NFSHomeDirectory
To get a rough list of Applications and their plists (note getting a list of everything installed is more complicated):
Dir.glob("/Applications/**/**app/Contents/Info.plist")

No comments: