Script to rename a list of files with a number sequence


Here is script that allows to bring some order to a list of randomly/uselessly named files or groups such as photo files coming directly from a camera memory card.
You need to specify the number of padding zeroes and a suffix.
Example results: 001 Topic, 002 Topic, 003 Topic, etc.
In case you need to add more files later to the same group, you can just rerun the script on the whole list of files to get them into a single sequence.

I hope this can be as useful to some of you as it is to me.
Best regards,
[Ed] Rename with a number sequence and a (18.8 KB)

1 Like

If you find this script useful, please drop a word on this thread.

And as this is a giving as well as a taking forum, here is another approach…

property lastValue : missing value
tell application id "DNtp"
	if selection ≠ {} then
		set incr to 1
		set {fname, numberPadding} to {word 1, word 2} of (text returned of (display dialog "Enter a common name followed by a comma and the number of zeroes to pad the prefixing number with." & return & return & "Ex. vacation,3" & return & "      0001 vacation.jpg, 0002 vacation.jpg,…" default answer "" & lastValue & ", 2" with icon 1))
		set lastValue to fname
		repeat with thisRecord in (selection as list)
			if (type of thisRecord ≠ group) and (type of thisRecord ≠ smart group) then
				set name of thisRecord to ((do shell script "printf %0" & (numberPadding as integer) & "d" & incr) & " " & fname as string)
				set incr to incr + 1
			end if
		end repeat
	end if
end tell


Interesting, thanks!