Created
January 20, 2011 00:00
-
-
Save angelo/787140 to your computer and use it in GitHub Desktop.
This ruby script finds unused image assets in a website project.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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