Batch Renaming Folders
Is there a way to batch replace current folder names with increasing numbers? The "Rename Finder Items" built-in feature only lets you replace in the 'Find and replace text' kind of way. Not all my current folder names have common characters. I'm using Mojave, btw.
Solution 1:
Here is an AppleScript solution that is quite efficient. You can save this code in script editor.app as an application.
set newName to 0
set theFolder to (choose folder with prompt "Choose Folder" with invisibles)
tell application "Finder"
set theFolders to folders of theFolder
set sortedFolders to sort theFolders by name
repeat with i from 1 to count of sortedFolders
set newName to newName + 1
set thisItem to item i of sortedFolders
set name of thisItem to newName
end repeat
end tell
If you would prefer the single digit folder names to appear as double digit (01,02,03 etc.), use this following version of the script instead
set newName to 0
set theFolder to (choose folder with prompt "Choose Folder" with invisibles)
tell application "Finder"
set theFolders to folders of theFolder
set sortedFolders to sort theFolders by name
repeat with i from 1 to count of sortedFolders
set newName to newName + 1
set thisItem to item i of sortedFolders
if newName is less than 10 then
set name of thisItem to 0 & newName as string
else
set name of thisItem to newName
end if
end repeat
end tell
This following AppleScript code will rename the files in the chosen folder, rather than renaming folders.
set newName to 0
set theFolder to (choose folder with prompt "Choose Folder" with invisibles)
tell application "Finder"
set theFiles to files of theFolder
set sortedFiles to sort theFiles by name
repeat with i from 1 to count of sortedFiles
set newName to newName + 1
set thisItem to item i of sortedFiles
set nameExtension to name extension of thisItem
if newName is less than 10 then
set name of thisItem to 0 & newName & "." & nameExtension as string
else
set name of thisItem to newName & "." & nameExtension as string
end if
end repeat
end tell
Solution 2:
Select all the folders you want to rename, right click them and select "Rename [number] Items..."
When you use the "Rename Finder Items" feature, you have to change it from "Replace Text" to "Format" in the drop down menu:
Now you can rename it however you want: