I am trying to make a script that will rename files in 2 seperate folders that end with H.jpg to W.jpg
Is the best way to run the routine on each folder seperately or can i run them together somehow?
I am having trouble with the offset command
I am sure it is something simple
attached is my script
setthesource_folder1to “Macintosh HD:Users:jbradfield:Desktop:Move to Thumbnail:” setthesource_folder2to “Macintosh HD:Users:jbradfield:Desktop:Move to Enlarged:”
I think you’re making your life much harder than it needs to be.
A much simpler solution would be something like (untested):
set source_folders to {"Macintosh HD:Users:jbradfield:Desktop:Move to Thumbnail:" , "Macintosh HD:Users:jbradfield:Desktop:Move to Enlarged:" }
tell application "Finder"
repeat with aFolder in source_folders
set filesToRename to every file of folder aFolder whose name ends with "H.jpg"
repeat with eachFile in filesToRename
set name of eachFile to ( characters 1 through -5 of (name of eachFile) & "W.jpg")
end repeat
end repeat
end tell
The tricks here are to use a whose clause to identify the files to rename (“every file… whose name ends with H.jpg”), then iterate through the list.
Additionally, since you know you’re removing the “H.jpg” at the end, you can use “characters 1 through -5” of the original file name. The “-5” works from the end of the filename, which is easier than trying to work some variable number of characters from the beginning.
Thank you very much for simplifying this for me
I tested the script and it returned:
. . . “Finder got an error: Can’t get characters 1 thru -5 of name of document file “AB3623_S002H.jpg” of folder “Move to Thumbnail” of folder “Desktop” of folder “jbradfield” of folder “Users” of startup disk.”
i tried to play with it but still reports error
any ideas?