Created
March 5, 2019 15:54
-
-
Save igolden/cd07c2b2d49f597e7937130b04cffa5d to your computer and use it in GitHub Desktop.
Traverse and rename files to slugs
This file contains hidden or 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
## | |
# Traverse and rename files | |
# | |
# - needs cleanup | |
require 'shellwords' | |
path = "src/assets/images/catalog" | |
folders = Dir.entries(path) | |
def rename(name) | |
name.gsub("&", "").gsub(" ", " ").gsub(" ", "-").gsub("---", "-").downcase | |
end | |
folders.drop(2).each do |f| | |
unless f == '.ds_store' || f == '.DS_Store' | |
dirpath = "#{path}/#{f}" | |
sub_entries = Dir.entries(dirpath).drop(2) | |
sub_entries.each do |sub| | |
cmd = "mv #{dirpath}/#{sub.shellescape} #{dirpath}/#{rename(sub)}" | |
system(cmd) | |
end | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment