Save the following little ruby script and execute it if you wish.
Code:
----- BEGIN SCRIPT -----
#!/usr/bin/ruby -w
#
# Following solution can be run from the command line, e.g.:
#
# $ ./this_program.rb "Black Cat"
#
def all_words_in_filename?(terms, filename)
result = false
# Each matching term cannot be followed by an
# alphanumeric value in the filename.
terms.each do |term|
if filename =~ /#{term}(?![a-z0-9])/i
result = true
else
result = false
break
end
end
return result
end
# Presumably, the following hard-coded array would be dynamically
# populated from reading a directory from disc.
file_list = [
'Black_Cat.jpg',
'Black Cat.jpg',
'Cat.jpg',
'Cat Is Black.jpg',
'Cat is black.jpg',
'Color - black.jpg',
'Black Catcher.jpg',
'Black cat22.jpg',
'Black Cat_22.jpg',
]
search_words = ARGV[0].to_s
if search_words.empty?
puts 'missing multi-word argument'
exit
end
terms = search_words.split(/\s+/)
i = 1
print "\nSearch Terms: #{terms.join(', ')}\n\n"
file_list.each do |file|
result = all_words_in_filename?(terms, file)
a = result ? '*' : ''
number = (a + i.to_s).rjust(2)
puts " #{number}. #{result.to_s.ljust(5)} #{file}"
i += 1
end
----- END SCRIPT -----