require 'find' def find_and_print(path, pattern) Find.find(path) do |entry| if File.file?(entry) and entry[pattern] has_transparency = `identify -format %A #{entry}` if has_transparency.to_s.chomp.strip == "True" puts "#{entry}" end end end end # print all the ruby files find_and_print("/rails_app/public/images", /.+\.png$/)