Walk a directory/Recursively: Difference between revisions

m
→‎{{header|Ruby}}: use lang tag
No edit summary
m (→‎{{header|Ruby}}: use lang tag)
Line 435:
=={{header|Ruby}}==
Pattern matching using regular expressions
<lang ruby> #define a recursive function that will traverse the directory tree
def printAndDescend(pattern)
#we keep track of the directories, to be used in the second, recursive part of this function
Line 452:
end
#print all ruby files
printAndDescend(/.+\.rb$/)</lang>
 
Or use the Find core Module
<lang ruby> require 'find'
def find_and_print(path, pattern)
Line 467:
# print all the ruby files
find_and_print(".", /.+\.rb$/)</lang>
 
Or, to find and print all files under '/foo/bar' the easy way:
<lang ruby> Dir.glob( File.join('/foo/bar', '**', '*') ) { |file| puts file }</lang>
 
=={{header|Scala}}==
Anonymous user