Skip to content

Instantly share code, notes, and snippets.

@byingyang
Created March 12, 2009 20:51
Show Gist options
  • Save byingyang/78278 to your computer and use it in GitHub Desktop.
Save byingyang/78278 to your computer and use it in GitHub Desktop.
Displays the file names of files that are not found in any documents under the given search directories
#!/usr/bin/env ruby
def unused_images(image_path_dir, search_dirs)
img_fns = Dir.glob("#{image_path_dir}**/*.*")
search_dirs.each {|sd| img_fns.delete_if{|img_fn| `grep -r '#{File.basename(img_fn)}' #{sd}` != ""}}
return img_fns
end
if ARGV.size < 2
puts "Usage: image_cleanup path_to_images path_to_search ..."
exit 1
end
image_path = ARGV.shift
unused_images(image_path, ARGV).each do |fn|
puts fn
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment