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
Post a Comment