Move files if file name doesn't exist considering extension For example, in folder A, I have foo.jpg and bar.jpg. In folder B, I have foo.png and foobar.png. I only need one version of the file regardless of the extension, so I only want move foobar.png to folder A. How can I do this? This is a simple example, there are almost 2,000 files in folder B, so comparing manually would be very tedious.
Save the following as a text file and make it executable. Invoke it from the command line, passing in the paths to folder A and folder B.

#!/usr/bin/ruby

if ARGV.size != 2
    STDERR.print "#Usage: #{$0} source/folder destination/folder\n"
    exit 1
end

a = ARGV[0].chomp("/")
b = ARGV[1].chomp("/")
old_bases = Hash.new
Dir.foreach(b) do |f| 
    next if f =~ /^\./
    old_bases[f.sub(/\.[^.]*$/, "").downcase] = true
end
Dir.foreach(a) do |f|
    next if f =~ /^\./
    fbase = f.sub(/.[^.]*$/, "").downcase
    unless old_bases[fbase]
        File.rename( "#{a}/#{f}", "#{b}/#{f}" )
        old_bases[fbase] = true
    end
end


Script edited to check number of arguments, and fix error in File.rename

Edited again to ignore case. That is, don't move Bar.png if bar.jpg already exists.