Last active
January 15, 2018 09:15
-
-
Save Kequc/8740833 to your computer and use it in GitHub Desktop.
Rename directory of files in random order to simple numerical form
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
require 'fileutils' | |
# Set folder path | |
folder_path = "/User/absolute/path/to/dir" | |
# Start at number | |
start = 0 | |
# Group into directories of size | |
size = 125 | |
# "%07d" for 7 digits ie 0000001.jpg | |
padding = "%07d" | |
# Then run this monster | |
Dir.glob("#{folder_path}/*").shuffle.each_with_index { |f,i| path = folder_path + "/" + (padding % (((i + start) / size).round * size)); FileUtils.mkdir_p(path); File.rename(f, path + "/" + (padding % (i + start)) + File.extname(f)) } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment