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

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -