我试图找到与某个文件扩展名匹配的目录和所有子目录中的所有文件,但忽略与忽略数组中的任何元素相匹配的文件。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