4

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.

4

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

enter image description here

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
  • Thank you! How would I edit this to work for images? Or, individual files instead of folders? – usuallystuck Dec 24 '18 at 16:58
  • 1
    @usuallystuck I added a third version of the code to rename files instead of folders – wch1zpink Dec 24 '18 at 17:54
  • Thanks, you're the best. Happy Holidays! – usuallystuck Dec 24 '18 at 18:05
5

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:

enter image description here

Now you can rename it however you want:

enter image description here

(I'll add better images later)

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.