Skip to content

Instantly share code, notes, and snippets.

@brettchalupa
Created February 11, 2022 23:03
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 brettchalupa/1016f645a46b5be9165a925ec3c017b9 to your computer and use it in GitHub Desktop.
Save brettchalupa/1016f645a46b5be9165a925ec3c017b9 to your computer and use it in GitHub Desktop.
Wordpress image export filename clean up
# A simple script for cleaning up Wordpress file exports that have URL params potentially appended to the end, e.g. `foo.jpg?w=720`
# Assumes the files are located in the `assets` dir
require "fileutils"
def clean_up_files(dir)
Dir.foreach(dir) do |f|
next if f == "." || f == ".."
path = dir + "/" + f
puts path
if File.directory?(path)
clean_up_files(path)
else
parts = path.split(".")
ext = parts.last
if path.include?("?")
File.rename(path, path.split("?").first)
end
end
end
end
clean_up_files("assets")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment