Thursday, December 13, 2018

#1 2018-11-20 02:20:05 pm

JoshuaTreeKC
Member
Registered: 2011-07-20
Posts: 4

Applescript - Change file names, multiple sub-folders move to new

Hello MacScripter Community,
I have searched for a long time but can’t find posts to help me accomplish what I need to do specifically.
I have an ongoing project where I have to manually sort photos into a folder of sub-folders. This folder structure is constant. After I sort them, I would like to use Applescript to change file names then move them to a single folder, “00-Complete”. I’m adding an example below.

Basically, I need to remove the first 7 characters of each file name then add “_01, _02, _03” etc. to each file within it’s respective sub-folder so they remain in the same sort order. Then move them to the "00-Complete" folder.

Photo-Set-Snapshot-all bbcode test

Offline

 

#2 2018-11-20 02:48:45 pm

StefanK
Member
From:: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 11526
Website

Re: Applescript - Change file names, multiple sub-folders move to new

Try this, you will be prompted to select the parent folder of the image folders

Applescript:

set baseFolder to choose folder

tell application "Finder" to set imageFolders to folders of baseFolder
repeat with aFolder in imageFolders
   if name of aFolder starts with "00" then
       set completeFolder to contents of aFolder
   else
       set prefix to text 1 thru 2 of (get name of aFolder)
       tell application "Finder" to set allImages to files of aFolder
       repeat with aFile in allImages
           tell application "Finder" to set {name:fileName, name extension:fileExtension} to aFile
           set baseName to text 1 thru ((get offset of "." & fileExtension in fileName) - 1) of fileName
           set newName to text 8 thru -1 of baseName & "_" & prefix & "." & fileExtension
           tell application "Finder"
               set movedFile to move aFile to completeFolder
               set name of movedFile to newName
           end tell
       end repeat
   end if
end repeat

Last edited by StefanK (2018-11-20 02:51:15 pm)


regards

Stefan

Online

 

#3 2018-12-05 09:50:11 am

JoshuaTreeKC
Member
Registered: 2011-07-20
Posts: 4

Re: Applescript - Change file names, multiple sub-folders move to new

StefanK, Thank you very much!

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)