What is the difference between:
Dir.glob(File.join('.', '**', '*')).each do |e|
end
and
require 'find'
Find.find('.').each do |e|
end
Despite the fact that Find is 3 times slower.
"Globbing" files (with Dir. glob) in Ruby allows you to select just the files you want, such as all the XML files, in a given directory.
pwd : To check the current working directory, pwd(present working directory) method is used. 5. chdir : To change the current working directory, chdir method is used.
Dir.glob
iterates over all files/directories that match the argument possibly including wild characters in a flat way, whereas Find.find
first iterates over a direct files/directories that match the exact path name, then looks into its direct files/directories in a recursive way. With Find.find
, you can skip the whole directory.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With