[plug] Find similarly named files in directories

Lyndon Maydwell maydwell at gmail.com
Fri Jan 12 15:39:09 WST 2007


I'm sure there must be a way to do this with rsync or diff...
But if not, anyone up for some golf?

same.rb=<<endcode
#!/usr/bin/ruby
list = $*.inject([]) { |a,e| File::directory?(e) ? a << Dir["#{e}/*"].map {|f|
 File::split(f).last} : a }
slist = list.inject(list[0]) {|a,e| e.length < a.length ? e : a}
list.flatten!
found = slist.find_all {|f1| list.find_all {|f2| f2 == f1}.length == $*.length}
puts found.join("\n") unless found.empty?
endcode



More information about the plug mailing list