Get folder files recursively in Ruby, without empty folders


I’ve used the code below to retrieve the files from a folder recursively when I needed to process only the files, but not the subfolders.
The files from subfolders are also included, but not the directories, I wanted especially to omit ” . ” and ” .. ” :

@files = ::Dir.glob(::File.join(source_folder, ‘**/*’), ::File::FNM_DOTMATCH).reject { |p| p }

Note 1: Credits go to StackOverflow, IT blogs and alike, sites that helped me with the code when searching for solutions.
Note 2: Be aware that when copy-pasting, the quotes and possibly other characters get messed up by WordPress, you’ll have to replace them.

%d bloggers like this: