Somewhere I’ve seen a script which renames files with an increasing number attached.
e.g. Filename 001
Filename 002
Filename 003 etc.
Could anyone please help me.
Thanks.
: Somewhere I’ve seen a script which renames files with an
: increasing number attached.
: e.g. Filename 001
: Filename 002
: Filename 003 etc.
: Could anyone please help me.
: Thanks.
add_leading_zeros routine taken from the AppleScript Guidebook Modules.
tell application "Finder"
set theList to every file in folder (choose folder)
try
set theList to sort theList by name -- optional
set int3 to 0
repeat with theFile in theList
set int3 to int3 + 1
set nName to name of theFile & " " & add_leading_zeros(int3, 2) of me -- 2 for 2 zeros
set name of theFile to nName
end repeat
end try
end tell
on add_leading_zeros(this_number, max_leading_zeros)
set the threshold_number to (10 ^ max_leading_zeros) as integer
if this_number is less than the threshold_number then
set the leading_zeros to ""
set the digit_count to the length of ((this_number div 1) as string)
set the character_count to (max_leading_zeros + 1) - digit_count
repeat character_count times
set the leading_zeros to (the leading_zeros & "0") as string
end repeat
return (leading_zeros & (this_number as text)) as string
else
return this_number as text
end if
end add_leading_zeros
: Somewhere I’ve seen a script which renames files with an
: increasing number attached.
: e.g. Filename 001
: Filename 002
: Filename 003 etc.
: Could anyone please help me.
: Thanks.
on open thoose_files
set leading_zeros to 3
repeat with x from 1 to count thoose_files
set the_index to x as string
repeat while ((count the_index) < leading_zeros)
set the_index to "0" & the_index
end repeat
tell application "Finder"
set name of item x of thoose_files to (name of item x of thoose_files) & space & the_index
end tell
end repeat
end open
Jean-Baptiste LE STANG