Created
February 11, 2022 23:03
-
-
Save brettchalupa/1016f645a46b5be9165a925ec3c017b9 to your computer and use it in GitHub Desktop.
Wordpress image export filename clean up
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
# 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