I have thousands of files I have imported to DTPO 2. Unfortunately, over the past several years, I have not been entirely consistent in my naming protocols, particularly in regards to dates. My general name format is:
(Filename)(space)(date)
with the filename of variable length, and with the date consisting of one of the following formats:
Two-digit year
x-x-xx
x-xx-xx
xx-x-xx
xx-xx-xx
Four-digit year
x-x-xxxx
x-xx-xxxx
xx-x-xxxx
xx-xx-xxxx
So, basically, every configuration of one- or two-digit months, one- or two-digit days, and two- or four- digit years. The vast majority are in two-digit year format. Unfortunately, this is the result of adding files over years, and not maintaining consistency. My bad!
Since really honing in on using DT, and poring over the forum, I have found I quite like Master Bill’s date format:
YYYYMMDD
without hyphens, slashes, etc.
So I have two problems:
- I am not sure how to get the individual filename into AppleScript, so I can run this manipulation on that name, then add the new name back to the filename;
- I would like to select a group of files and run the script on each consecutively;
- (This is likely the hard part) I would like to create variable so that any of the above date formats will be corrected to my new format.
I had an expert help me with such a script in Finder, with excellent results:
tell application "Finder" to set theSelection to (get selection)
repeat with oneItem in theSelection
set {name:Nm, name extension:Ex} to (info for oneItem as alias)
set filename to text 1 thru ((get offset of "." & Ex in Nm) - 1) of Nm
if Ex is missing value then set Ex to ""
if Ex is not "" then set Ex to "." & Ex
set {TID, text item delimiters} to {text item delimiters, space}
tell filename to set {theName, theDate} to {(text items 1 thru -2) as text, text item -1}
set text item delimiters to "-"
set {mn, dy, yr} to text items of theDate
set text item delimiters to TID
if (count yr) = 2 then set yr to "20" & yr
tell application "Finder" to set name of contents of oneItem to theName & space & yr & my pad(mn) & my pad(dy) & Ex
end repeat
on pad(t)
return text -2 thru -1 of ("0" & t)
end pad
If I use this in Finder, it works perfectly. Unfortunately, I tried it within DTPro Office, and am running into some problems. And the expert does not know DT.
I have tried to open the information window, copy the name, manipulate the name using the above script, and then pasting it back. No dice.
Any help from our resident mavens?
Cheers!