Here’s the deal…
We have hundreds of folders with thousands of job folders in them. We have changed naming convention on these job folders and I would like to go back with a script and make all the old folder names use the same convention. The old convention was to use CUSTOMER_NAME + JOB_NUMBER and the new convention is the reverse… JOB_NUMBER + CUSTOMER_NAME.
My question is, what scripting would I use to determine where and what the job number is. Some of the job numbers are 5 digits at the end, some are 6 digits. Some of the folders don’t have job numbers on them at all. It would be nice to make sure that there are no blank spaces at the end while I’m at it, but that’s not necessary.
set a to "ANIMALS 22459
B_Dalton_final
CSI 22292
Sundeck 100142"
set b to paragraphs of a
set {TID, text item delimiters} to {text item delimiters, space}
repeat with i in b
try
set newName to text item 2 of i & space & text item 1 of i
display dialog newName
-- code to rename file
on error
-- no need to change the name
end try
end repeat
set text item delimiters to TID
ok… I get that, but how do I handle file names that have multiple spaces…
THIS JOB NAME 12345
and what would happen to the file names that have two words, but no numbers…
MY TRADE SHOW SIGNS
is there a way to easily figure out that the last “word” in this case is actually just all numbers? At least then I could say that if the last text item is all numbers, THEN move it to the front.
set a to "ANIMALS 22459
B_Dalton_final
CSI 22292
Sundeck 100142
THIS JOB NAME 12345
MY TRADE SHOW SIGNS"
set b to paragraphs of a
set {TID, text item delimiters} to {text item delimiters, space}
repeat with i in b
try
(last text item of i) as integer
tell i to set newName to last text item & space & text items 1 thru -2 as text
display dialog newName
-- code to rename file
on error
-- no need to change the name
end try
end repeat
set text item delimiters to TID
set nameSeeds to {"THIS JOB NAME 12345", "MY TRADE SHOW SIGNS"}
on isLastWordNumber(theString)
set lastWord to word -1 of theString
try
lastWord as number
return true
on error
return false
end try
end isLastWordNumber
my isLastWordNumber(item 1 of nameSeeds)
--true
my isLastWordNumber(item 2 of nameSeeds)
--false