Ruby文件列表排除了一个文件夹

icn*_*icn 7 ruby rake filelist

以下是我尝试过的所有事情:

  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
Run Code Online (Sandbox Code Playgroud)

rake版本是0.9.2.2,Ruby版本是193.所有都不起作用.我该如何排除文件列表中的目录?

mae*_*ics 7

我假设您正在尝试获取所有文件的列表,c:/tmp除了c:/tmp/logs文件夹中的任何内容(包括):

files = FileList.new("c:/temp/**/*").exclude(/c:\/temp\/logs/)
Run Code Online (Sandbox Code Playgroud)

[编辑]有关FileList#exclude详细信息,请参阅文档.例如,要排除多个目录,可以添加多个字符串/正则表达式参数,修改正则表达式以匹配要排除的所有目录模式,或者在块中执行类似的操作.

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)
Run Code Online (Sandbox Code Playgroud)