I'm trying to set the file title of selected PDF files to their ModifiedDate. I have spent many hours reading about various ways to use SetAttr, read through the code of Albator V's toolbar, and read posts such as the following:
[url]Rename scripts in JScript, VBScript and PerlScript]
[url]File name to modified date/time?]
I'm quoting these two as they were the most instructive, but I've read many others too.
I am able to set the title easily using SetAttr, but only to a static value. The problems I'm facing is that a SetAttr doesn't seem to allow me to embed external information, such as another metadata field. I tried verious permutations of SetAttr META "title:{modifieddate|D#yyyyMMddT#HHmmss} FILEINFO" but to no avail.
I tried to adapt the code found in that last post quoted above to my needs:
dim DOpusRTPath
DOpusRTPath = "%ProgramFiles%\GPSoftware\Directory Opus\dopusrt.exe"
Dim Shell
Set Shell = CreateObject("WScript.Shell")
Function Rename_GetNewName(strFileName, strFilePath, fIsFolder, strOldName, ByRef strNewName)
Dim strDateTime
Dim strCommand
' Set strNewName to an empty string so that Opus does not rename the file.
strNewName = ""
' Set strDateTime to file's ModifiedDate. This is a placeholder.
strDateTime = "2013-09-15 21:57:00"
' DOpus.OutputString "DT = " & strDateTime
strCommand = """" & DOpusRTPath & """ /cmd SetAttr FILE=""" & strFilePath & "\" & strFileName & """ META """ & title: & strDateTime & """"
' DOpus.OutputString "CMD = " & strCommand
Shell.Run strCommand,0,true
End Function[/code]
It doesn't work, but even if it did I still have to embed the data from another metadata field, and I can't find how to read those.
Some more research and borrowing from Leo produced the following solution:
[code]Rename PATTERN=".PDF" TO=".PDF" @script vbscript
Option Explicit
' For information on the technique used in this button see:
' "Abusing" Rename Scripts to do other things with file info
' [OBSOLETE] "Abusing" Rename Scripts to do other things with file info
' Change the path below if you haven't installed Opus to the default location:
dim DOpusRTPath
DOpusRTPath = "%ProgramFiles%\GPSoftware\Directory Opus\dopusrt.exe"
Dim Shell
Set Shell = CreateObject("WScript.Shell")
Function Rename_GetNewName(strFileName, strFilePath, fIsFolder, strOldName, ByRef strNewName)
Dim strDateTime
Dim strCommand
Dim objFSO
Dim objFile
Dim dyear
Dim dmonth
Dim dday
Dim dhour
Dim dmin
Dim dsec
' Set strNewName to an empty string so that Opus does not rename the file.
strNewName = ""
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile(strFilePath & "\" & strFileName)
' Get date into a string like "YYYY-MM-DD HH:MM:SS"
dyear = CStr( Year( objFile.DateLastModified ) )
dmonth = CStr( Month( objFile.DateLastModified ) )
dday = CStr( Day( objFile.DateLastModified ) )
dhour = CStr( Hour( objFile.DateLastModified ) )
dmin = CStr( Minute( objFile.DateLastModified ) )
dsec = CStr( Second( objFile.DateLastModified ) )
strDateTime = String(4-Len(dyear),"0") & dyear & "-" & String(2-Len(dmonth),"0") & dmonth & "-" & String(2-Len(dday),"0") & dday & " " & String(2-Len(dhour),"0") & dhour & ":" & String(2-Len(dmin),"0") & dmin & ":" & String(2-Len(dsec),"0") & dsec
' Set strDateTime to file's ModifiedDate
' strDateTime = objFile.DateLastModified
' DOpus.OutputString "DT = " & strDateTime
strCommand = """" & DOpusRTPath & """ /cmd SetAttr FILE=""" & strFilePath & "\" & strFileName & """ META=""title:" & strDateTime & """"
' DOpus.OutputString "CMD = " & strCommand
Shell.Run strCommand,0,true