这是我尝试过的所有方法:

  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版本是0.9.2.2,而Ruby版本是193。
都行不通。如何排除文件列表中的目录?

最佳答案

我假设您正在尝试获取c:/tmp下所有文件的列表,但c:/tmp/logs文件夹中的所有文件除外(包括):

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

[编辑] 有关更多详细信息,请参见 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)

关于ruby - Ruby文件列表排除文件夹,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8900623/

10-14 17:01
查看更多