Skip to content

Instantly share code, notes, and snippets.

@dmcclory
Created August 22, 2012 22:08
Show Gist options
  • Save dmcclory/3429881 to your computer and use it in GitHub Desktop.
Save dmcclory/3429881 to your computer and use it in GitHub Desktop.
functions which return all the files or all of the directories contained within a Pathname
def collect_files(pn)
if pn.file?
return pn
end
pn.children.collect {|cn| collect_files(cn)}.flatten
end
def collect_directories(pn)
if pn.directory?
pn.children.collect {|cn| collect_directories(cn)}.flatten.reject{|i| i.nil?}.push(pn)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment