Register now and start sharing your code snippets.
-->
A Ruby script that deletes images that are not used anywhere
Ruby posted 6 months ago by christian
1 Dir.glob("**/*.{jpg,gif,jpeg,png}").sort.each do |image| 2 3 name = File.basename(image) 4 in_use = false 5 6 Dir.glob("**/*.{erb,css,js,html,htm}").each do |file| 7 contents = File.read(file) 8 9 in_use = contents.include?(name) 10 11 break if in_use 12 end 13 14 if !in_use 15 puts "Deleting '#{image}'" 16 File.delete(image) 17 end 18 end