[plug] Find similarly named files in directories

Timothy White weirdit at gmail.com
Fri Jan 12 18:04:58 WST 2007


What do you define as similar?
And as I don't read ruby, so just to make sure, your not trying to
find duplicates in different directories are you?

Tim

On 1/12/07, Lyndon Maydwell <maydwell at gmail.com> wrote:
> 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
> _______________________________________________
> PLUG discussion list: plug at plug.org.au
> http://www.plug.org.au/mailman/listinfo/plug
> Committee e-mail: committee at plug.linux.org.au
>


-- 
Linux Counter user #273956
Don't email joeblogs at scouts.org.au



More information about the plug mailing list