Skip to content

Instantly share code, notes, and snippets.

@Yukaii
Last active August 29, 2015 14:09
Show Gist options
  • Save Yukaii/60c2b226f57d34f264ff to your computer and use it in GitHub Desktop.
Save Yukaii/60c2b226f57d34f264ff to your computer and use it in GitHub Desktop.
a simple snippets for traversing all sub directories
# usage:
#
# dir_traversal do
# the_code_want_to_run_in_each_directory
# end
def self.dir_traversal
Dir.glob("*").each do |name|
if File.directory?(name)
Dir.chdir(name)
dir_traversal { yield }
end
end
yield
Dir.chdir("..")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment