Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Cleanup undeleted paperclip files from the filesystem
a = Dir[Rails.root.join('public/system/photos/original/*').to_s]; 1
not_exists = {|v| v.match(/\/([^\/]+)\.[^\/]*\z/).to_a[1].to_i } - Photo.pluck(:id)
files = Dir[Rails.root.join('public/system/photos/**/*').to_s]; 1
match ="\/(#{not_exists.join('|')})\\.[^\/]*\\z")
matched = {|v| v =~ match }; 1 {|v| File.stat(v).size }.inject(:+)
# TO DELETE UNCOMMENT FileUtils.rm(matched)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment