Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save underscorebrody/6e810622b095cb21704d8b0ea96915fa to your computer and use it in GitHub Desktop.
Save underscorebrody/6e810622b095cb21704d8b0ea96915fa to your computer and use it in GitHub Desktop.
Rake task to find unused images on Rails project to deletion.
# It requires ACK - http://betterthangrep.com/
task :find_unused_images do
images = Dir.glob('app/sources/images/**/*')
images_to_delete = []
filelist = `cd .. && ack -g -i '(my-app/app|my-app/public|my-gem/app)'`
images.each do |image|
unless File.directory?(image)
# print "\nChecking #{image}..."
print "."
result = `cd .. && echo "#{filelist}" | ack -x -w #{File.basename(image)}`
# print "Found: #{result}" unless result.empty?
if result.empty?
images_to_delete << image
else
end
end
end
puts "\n\nDelete unused files running the command below:"
puts "rm #{images_to_delete.join(" ")}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment