Created
June 27, 2022 22:02
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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