Skip to content

Instantly share code, notes, and snippets.

@digitaljhelms
Forked from angelo/img_coverage.rb
Created May 9, 2011 17:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save digitaljhelms/962889 to your computer and use it in GitHub Desktop.
Save digitaljhelms/962889 to your computer and use it in GitHub Desktop.
finds unused image assets in a website project.
#!/usr/bin/env ruby
require 'fileutils'
files = Dir['**/*.{htm,html,shtml,php,css,js}']
images = Dir['**/*.{jpg,png,gif,bmp}']
puts "#{images.size} images found & #{files.size} files found to search against"
content = ""
files.each do |filename|
content << File.read(filename)
end
images.each do |filename|
basename = File.basename filename
dirname = File.dirname filename
image_not_used = content !~ /\b#{basename}\b/
if image_not_used
FileUtils.mkdir_p "../unused/#{dirname}"
FileUtils.mv filename, "../unused/#{filename}"
puts "Image '#{filename}' moved to '../unused' folder"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment