I'd like to update the modified date (year) after year in filename.
filenames are as follows (examples) (99% are pdf-files)
Report about this and that 1983.pdf
or
Some other report covering period 2001-2010.pdf
It is either 19xx or 20xx
In regex I came as far as extracting the year:
find: ^(?:.*?)[-\s]*([12][90][0-9][0-9])(\.(?:.*?))$
replace: \1
vainly tried to update an existing script, changing modified date after date in filename.
that script uses full date (dd mm yyyy).
the modified date was changed, but the results were some weird years, like 03-03-1690.
Rename PATTERN="*" TO="*"
@script vbscript
Option Explicit
' 06-02-2018
' Opus toolbar-button : Year from Filename
' Based on: Change modified date after filename thread - script from MrC
' For information on the technique used in this button see:
' "Abusing" Rename Scripts to do other things with file info
' https://resource.dopus.com/t/obsolete-abusing-rename-scripts-to-do-other-things-with-file-info/5969
' Change the path below if you haven't installed Opus to the default location:
dim DOpusRTPath
'DOpusRTPath = "C:\Program Files\GPSoftware\Directory Opus\dopusrt.exe"
DOpusRTPath = "D:\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 = ""
Dim debstr
Dim gettimestamp
gettimestamp = 0
' year from filename
' e.g. Some file name with Year at the end 1980-1999.pdf
' or Some other file name with Year at the end 2013.pdf
Dim reA
Set reA = new RegExp
reA.Pattern = "^(?:.*?)[-\s]*([12][90][0-9][0-9])\.(?:.*?)$"
If (reA.Test(strFileName)) Then
strDateTime = reA.Replace(strFileName, "01-01-$1")
gettimestamp = 1
debstr = "(A): " & strDateTime
End If
If (Not IsEmpty(strDateTime)) Then
If (gettimestamp) Then
strDateTime = strDateTime & " " & GetFileModTime(strFilePath & "\" & strFileName)
End If
'DOpus.OutputString "Set Date & Time " & debstr
strCommand = """" & DOpusRTPath & """ /cmd SetAttr FILE=""" & strFilePath & "\" & strFileName & """ MODIFIED=""" & strDateTime & """"
'DOpus.OutputString "CMD = " & strCommand
Shell.Run strCommand,0,true
End If
End Function
Function GetFileModTime(filespec)
Dim fso, f, s
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFile(filespec)
s = split(f.DateLastModified, " ", -1, 1)
GetFileModTime = s(1)
End Function
Annual Report 1977.pdf modified date to change tot 01-01-1977
Bundled Reports covering period 1976-2005.pdf modified date to change to 01-01-2005
Bundled Reports period 1976-1983.pdf modified date to change to 01-01-1983
i.e. modified date based on the the 4 digits before the extension, only starting with either 19 or 20, plus 01-01-
Note: I also tried just $1 in the as replace, but that didn't work out either.
Thanks in advance for suggestions.
LATER
I think I have found a 3 step workaround
regex rename
fm: Annual Report 1981.pdf
to: Annual Report 01011981.pdf
or
fm: Bundled Reports period 1976-1983.pdf
fm: Bundled Reports period 1976-01011983.pdf
find: ^(.*?)([-\s])([12][90][0-9][0-9])(\.(?:.*?))$
repl: $1$20101$3$4
then 2. do change modified date based on date in filename (existing button, script)
then 3. rename files back again
find: ^(.*?)([-\s])0101([12][90][0-9][0-9])(\.(?:.*?))$
repl: $1$2$3$4
I admit, it isn't a nice solution.
regretfully I can not delete my earlier post...