Skip to content

Instantly share code, notes, and snippets.

@theHamdiz
Created February 23, 2015 11:54
Show Gist options
  • Select an option

  • Save theHamdiz/bc175887d77f76ee9e41 to your computer and use it in GitHub Desktop.

Select an option

Save theHamdiz/bc175887d77f76ee9e41 to your computer and use it in GitHub Desktop.
Rename files in any given directory
puts 'Renaming files...'
# a parameter to the program from command line.
folder_path = ARGV[0] # /Users/a7madx7/Pictures/WallPapers
Dir.glob(folder_path + "/*").sort.each_with_index do |f, i|
# prepare a the brand new 'renamed' complete file path.
new_name = File.dirname(f) + '/' + i.to_s + File.extname(f)
# do the actual renaming of the file.
File.rename(f, new_name)
end
puts 'Renaming completed!'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment