Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby filelist exclude a folder

Here are all things I have tried:

  files = FileList.new("c:/temp/**/*") do |file|
    file.exclude("c:/temp/logs/")
  end


files = FileList.new("c:/temp/**/*") do |file|
  file.exclude("c:/temp/logs")
end

  files = FileList.new("c:/temp/**/*") do |file|
    file.exclude("c:/temp/logs/*.*")
  end


  files = FileList.new("c:/temp/**/*") do |file|
    file.exclude("c:/temp/logs/**/*")
  end


  files = FileList.new("c:/temp/**/*") do |file|
    file.exclude("c:/temp/**/logs/")
  end

rake version is 0.9.2.2 and Ruby version is 193. all doesn't work. How should I exclude a directory in a filelist?

like image 754
icn Avatar asked Jan 17 '12 19:01

icn


1 Answers

I'm assuming you're trying to get a listing of all files under c:/tmp except for anything in (and including) the c:/tmp/logs folder:

files = FileList.new("c:/temp/**/*").exclude(/c:\/temp\/logs/)

[Edit] See the documentation for FileList#exclude for more details. For example, to exclude multiple directories you can either add multiple string/regex arguments, modify the regular expression to match all directory patterns to be excluded, or do something similar in a block.

x1 = /c:\/temp\/logs/ # The entire "c:/temp/logs" folder.
x2 = /\.zip$/i # Any file whose name ends with ".zip".
FileList.new("c:/temp/**/*").exclude(x1, x2)
like image 173
maerics Avatar answered Nov 04 '22 19:11

maerics