Shilpi Agrawal
Shilpi Agrawal

Reputation: 615

Ignore Hidden files using regex

I have some line of code which retrieves all the files from one folder. But its also fetching hidden files. Can someone help me in modifying that regular expression so, that it won't retrieve hidden files?

Find.find(actual_root) do |path|
         file_paths << path if path =~ /.*\./
        end

Upvotes: 2

Views: 901

Answers (1)

Maxim
Maxim

Reputation: 9981

This line return all files and directories (exclude hidden) in actual_root:

Dir[File.join(actual_root, '*')]

Use this if you want to take files only:

Dir[File.join(actual_root, '*')].select { |f| File.file?(f) }

Upvotes: 2

Related Questions