file - Filename increment in applescript -
i'm after lightweight automator process (applescript) detect filenames "file_v01", "document_v03" ending in "_vxx" incremented (to "file_v02" , there suprisingly little content out there on this.
i have attempted detecting , removing last 2 characters filename no avail, , thoughts great. doesnt need fancy, _v02 becomes _v03.
any great!!
here applescript automator increment last 2 characters filename
on run {input, parameters} tell application "system events" repeat thisfile in input set {tname, nameext} {name, name extension} of thisfile if nameext not "" set nameext "." & nameext set newname incrementnumber(tname, nameext) if newname not "" -- last 2 characters number set name of thisfile newname end if end repeat end tell return input end run on incrementnumber(n, e) -- name , name extension set tbase text 1 thru ((length of n) - (length of e)) of n -- name without extension try set thisnumber (text -2 thru -1 of tbase) + 1 -- last 2 characters , increment if thisnumber < 10 set thisnumber "0" & thisnumber -- 0 padding set tbase text 1 thru -3 of tbase -- remove last 2 characters return tbase & thisnumber & e -- updated name (the basename without last 2 characters + number + extension) end try return "" -- last 2 characters not number end incrementnumber
Comments
Post a Comment