Created
February 23, 2015 11:54
-
-
Save theHamdiz/bc175887d77f76ee9e41 to your computer and use it in GitHub Desktop.
Rename files in any given directory
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
| 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