Apologies if this is posted in the wrong place. I'm hoping someone can assist me with the following script which was kindly written for me a while ago. It worked for ages but now produces an error message. Does it need tweaking or rewriting?

I use the script to automatically sort files into folders which are created from a selected number of letters from the filenames. AT the moment I'm getting the message...

"error "Finder got an error: Canít make \"500 Gb HUB 1ownloads:JD: Thumbs Created - CHECK: FACES:Manuelas-2" into type item." number -1700 from "500 Gb HUB 1ownloads:JD: Thumbs Created - CHECK: FACES:Manuelas-2:" to item"

Any help is much appreciated. Thanks.


set baseFolder to choose folder
set {ATID, AppleScript's text item delimiters} to {"", "-"}
tell application "Finder"
set theFiles to every file of entire contents of baseFolder as alias list

set s_c to text returned of (display dialog "Please enter the STARTING character:" default answer "")
set e_c to text returned of (display dialog "Please enter the ENDING character:" default answer "")
repeat with aFile in theFiles
set fileName to name of aFile
set collection to text s_c through e_c of fileName
set cont to container of aFile as string

if folder (cont & collection) exists then
make new folder at cont with properties {name:collection}
end if
-- The next line trims the file name as so given a file name "GroupAbcSubGroupDefViewXYZFile012345-0"
-- and entering Start: 9 End: 19 then when the file is moved the new name would be "SubGroupDefViewXYZFile012345-0"
-- To retain the text prior to the character start (assuming there is any) remove the following line.
-- set name of aFile to (text s_c through -1 of fileName)
move file aFile to (cont & collection & ":")
end repeat
end tell
set AppleScript's text item delimiters to ATID