我試圖找到與某個文件擴展名匹配的目錄和所有子目錄中的所有文件,但忽略與忽略數組中的任何元素相匹配的文件。Ruby在搜索中排除目錄和或文件
例子:
ignore = ['test.conf', 'another.conf']
的文件 'test.conf' 和 'another.conf' 應該被忽略。
到目前爲止,我有這樣的:
Find.find('./').select { |x|
x.match('.*\.conf$') # => only files ending in .conf
}.reject { |x|
# code to reject any files which match any elements from 'ignore'
}
我知道我可以做這樣的事情:
Find.find('./').select { |x|
x.match('.*\.conf')
}.reject { |x|
x.match('test.conf|another.conf')
}
但是,考慮有大量文件的陣列,並且不希望寫出所有文件(如上)
幫助讚賞。
如果'ignore'也可以包含您希望跳過的目錄名稱,那麼您希望的方法更健壯。 –
這是下一步,但我想先讓上述工作正常進行。謝謝你的建議:) – user2840647