Last active
August 29, 2015 14:09
-
-
Save Yukaii/60c2b226f57d34f264ff to your computer and use it in GitHub Desktop.
a simple snippets for traversing all sub directories
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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