I have a lot of folder that i have to change the name very often to upload it on an FTP.
The folder’s name are always written like this:
A project name, a space, open bracket “[”, a letter, 4 numbers, and a closing bracket “]” XXXXXXXXX [X0000]
I want to chage it to:
remove the brackets [ ] move the X and the 4 numbers at the beginning and add a “space dash space” between the first part and the last part. X0000 - XXXXXXXXX.
tell application "Finder"
set myFolder to folder ((path to desktop as text) & "abcdefg [h1234]")
set folderName to name of myFolder
set newName to do shell script "echo " & quoted form of folderName & " | sed 's/\\(.*\\)\\[\\(.*\\)\\]/\\2 - \\1/'"
--set name of myFolder to newName
end tell
set newName to my trickyNameChange("XXXXXXXXX [X0000]")
on trickyNameChange(old_Name)
local oTIDs, projName, code
set oTIDs to AppleScript's text item delimiters
set AppleScript's text item delimiters to " ["
set {projName, code} to text items of old_Name
set AppleScript's text item delimiters to oTIDs
return (text 1 thru -2 of code) & " - " & projName
end trickyNameChange
Yvan KOENIG (VALLAURIS, France) vendredi 12 octobre 2012 17:38:34