记录一下,类似需求日后拷皮修改就可以。
#encoding:utf-8
def search_file_by_type(source_dir,file_types,&block)
Dir.entries(source_dir).each do |file|
next if %w[. ..].include?(file)
if File.file?(source_dir + File::SEPARATOR + file)
file_types.split('|').each do |type_name|
if file.downcase.end_with?(type_name.downcase)
if block_given?
block.call source_dir + File::SEPARATOR + file
end
end
end
elsif File.directory?(source_dir + File::SEPARATOR + file)
if block_given?
search_file_by_type(source_dir + File::SEPARATOR + file,file_types,&block)
end
end
end
end
search_file_by_type('D:/OpenSource/lame-3.100','.c|.h') do |file|
puts file
end