7

ここに私が試したすべてのものがあります:

  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 です。すべてが機能しません。ファイルリストでディレクトリを除外するにはどうすればよいですか?

4

1 に答える 1

7

フォルダー内 (およびフォルダー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)
于 2012-01-17T19:43:13.533 に答える