Skip to content

Instantly share code, notes, and snippets.

@pburleson
Forked from breeno/xc-unused-images.rb
Created February 2, 2011 19:42
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 pburleson/808259 to your computer and use it in GitHub Desktop.
Save pburleson/808259 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# get all the file names we are interested in
source_filenames = Dir['**/*.m']
source_filenames.concat( Dir['**/*.xib'] )
png_filenames = Dir['**/*.png']
image_references = Hash.new
png_filenames.each { |filename| image_references[File.basename(filename.downcase)] = 0 }
# find all references to images in souces
source_filenames.each do |filename|
begin
file = File.open(filename, 'r')
contents = file.read.downcase
png_filenames.each do |image_filename|
base_image_filename = File.basename(image_filename).downcase
if contents.index(base_image_filename) != nil
image_references[base_image_filename] += 1
end
end
file.close
rescue
puts "Error opening #{filename}\n"
end
end
# show results
unused_image_count = 0
image_references.each do |filename,refcount|
if refcount == 0
puts "#{filename}\n"
unused_image_count += 1
end
end
puts " #{unused_image_count} unreferenced images out of #{png_filenames.count}.\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment