Created
November 17, 2021 01:25
-
-
Save shikelong/1a07dafd2771be95880db16e5b136e70 to your computer and use it in GitHub Desktop.
【Ruby】 Convert file name (a b.svg ==> a-b.svg)
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
puts "start convert file names to hyphen style...." | |
def traverse_dir(fileType) | |
folder_path = File.absolute_path("./") + "/" | |
scheme = folder_path + "*.#{fileType}" | |
puts "find #{Dir.glob(scheme).length} #{fileType} files, start convert...." | |
puts '-' * 50 | |
Dir.glob(scheme).each do |f| | |
filename = File.basename(f, File.extname(f)) | |
File.rename(f, folder_path + filename.downcase.tr(' ', '-') + File.extname(f)) | |
end | |
end | |
traverse_dir('svg') | |
puts '-' * 50 | |
puts "convert finished" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment