Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you filter Ruby Find.find() results?

Tags:

find

ruby

Find.find("d") {|path| puts path}

I want to exclude certain type of files, say *.gif and directories.

PS: I can always add code inside my block to check for the file name and directory type, but I want find itself to filter files for me.

like image 936
roshan Avatar asked Dec 16 '22 21:12

roshan


1 Answers

I don't think you can tell find to do that.You could try using Dir#[], which accepts file globs. If you are looking for particular types of files, or files that can be filtered with the file glob pattern language, it may be a better fit.

eg

Dir["dir/**/*.{xml,png,css,html}"]

would find all the xml, png, css, and html files under the directory d.

Check out the docs for more info.

like image 72
BaroqueBobcat Avatar answered Dec 19 '22 11:12

BaroqueBobcat