how to get files count in a directory using ruby -


using ruby how number of files in given directory,the file count should include count recursive directories.

eg: folder1(2 files) -----> folder2(4 files) , folder2 inside folder1. total count above case should 6 files.

is there function in ruby fetch me count.

the fastest way should (not including directories in count):

dir.glob(file.join(your_directory_as_variable_or_string, '**', '*')).select { |file| file.file?(file) }.count 

and shorter:

dir = '~/documents' dir[file.join(dir, '**', '*')].count { |file| file.file?(file) } 

Comments

Popular posts from this blog

php - How can I edit my code to echo the data of child's element where my search term was found in, in XMLReader? -

javascript - Iterate over array and calculate average values of array-parts -

jQuery Ajax Render Fragments OR Whole Page -