Skip to content

Instantly share code, notes, and snippets.

@shikelong
Created November 17, 2021 01:25
Show Gist options
  • Save shikelong/1a07dafd2771be95880db16e5b136e70 to your computer and use it in GitHub Desktop.
Save shikelong/1a07dafd2771be95880db16e5b136e70 to your computer and use it in GitHub Desktop.
【Ruby】 Convert file name (a b.svg ==> a-b.svg)
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