Skip to content

Instantly share code, notes, and snippets.

@massayoshi
Created June 27, 2022 22:02
Show Gist options
  • Save massayoshi/486bf0df2a4de4475acc44354c02f6c5 to your computer and use it in GitHub Desktop.
Save massayoshi/486bf0df2a4de4475acc44354c02f6c5 to your computer and use it in GitHub Desktop.
Script to cleanup the different image sizes wordpress creates and just keep the original file
#!/usr/bin/ruby
pattern = /-\d+x\d+\.(jpg|png|jpeg)/ # my-file-name-pattern-2000x2000.jpg
files = Dir.glob("/path/to/wordpress/wp-content/uploads/20XX/**/*.*")
files.sort!
files.each do |file|
if pattern =~ file
puts 'Deleting ' + file
File.delete(file)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment