Rename PATTERN="*" TO="*"
@script vbscript
Option Explicit
 
' Original script by MrC
' http://resource.dopus.com/viewtopic.php?f=3&t=19704&start=20#p106752
'
' Modified for DOpus 11
 
Dim file, strDateTime, attrcmd
 
' 10 digits, dash, 4 digits space dd-mm-yyyy.pdf
Dim reA
Set reA = new RegExp
reA.Pattern = "^\d{10}-\d{4} (\d{2})-(\d{2})-(\d{4})(?:.*?)$"
 
' Date / Scan Date pattern: dd mm yyyy ddmmyyyy, with possible space or dash separators in Date
Dim re0
Set re0 = new RegExp
re0.Pattern = "^(?:.*?)[-\s]*(\d{2})([-\s]*)(\d{2})\2(\d{4})[-\s]+(\d{8})(?:.*?)$"
 
' Date / Time pattern: dd mm yyyy hh mm ss, with possible space or dash separators
Dim re1
Set re1 = new RegExp
re1.Pattern = "^(?:.*?)[-\s]*(\d{2})([-\s]*)(\d{2})\2(\d{4})[-\s]+(\d{2})([-\s]?)(\d{2})\6(\d{2})(?:.*?)$"
 
' Date pattern: dd mm yyyy, with possible space or dash separators
Dim re2
Set re2 = new RegExp
re2.Pattern = "^(?:.*?)[-\s]*(\d{2})([-\s]*)(\d{2})\2(\d{4})(?:.*)$"
 
' Date / Time pattern: yyyy-mm-dd hh mm ss
Dim re3
Set re3 = new RegExp
re3.Pattern = "^(?:.*?)[-\s]*(\d{4}([-\s]*)\d{2}\2\d{2})[-\s]+(\d{2})([-\s]?)(\d{2})\4(\d{2})(?:.*?)$"
 
' Date pattern: yyyy-mm-dd
Dim re4
Set re4 = new RegExp
re4.Pattern = "^(?:.*?)[-\s]*(\d{4}([-\s]*)\d{2}\2\d{2})(?:.*)$"
 
Dim reTime
Set reTime = new RegExp
reTime.Pattern = "^(?:.*?)\s(\d{2}):(\d{2}):(\d{2})(?:.*)$"
 
DOpus.OutputString "---- DateFromName ----"
Function OnClick(ByRef ClickData)
 For Each file In ClickData.func.sourcetab.selected
'    If file.is_dir Then             ' --- Uncomment this and "End If" below if you only want it to act on folders
     DOpus.OutputString Q(file.path & file.name) & "|" & file.modify_utc & "|" & file.modify
     If (reA.Test(file.name)) Then
       strDateTime = reA.Replace(file.name, "$3$2$1")  
       strDateTime = strDateTime & " " & reTime.Replace(file.modify, "$1:$2:$3")
       DOpus.OutputString "Date A  = " & strDateTime
     ElseIf (re0.Test(file.name)) Then
       strDateTime = re0.Replace(file.name, "$4$3$1")  
       strDateTime = strDateTime & " " & reTime.Replace(file.modify, "$1:$2:$3")
       DOpus.OutputString "Date 0  = " & strDateTime
     ElseIf (re1.Test(file.name)) Then
       strDateTime = re1.Replace(strFileName, "$4$3$1 $5:$7:$8")
       DOpus.OutputString "Date 1  = " & strDateTime
     ElseIf (re2.Test(file.name)) Then
       strDateTime = re2.Replace(file.name, "$4$3$1")
       strDateTime = strDateTime & " " & reTime.Replace(file.modify, "$1:$2:$3")
       DOpus.OutputString "Date 2  = " & strDateTime
     ElseIf (re3.Test(file.name)) Then
       strDateTime = re3.Replace(file.name, "$1 $3:$5:$6")
       DOpus.OutputString "Date 3  = " & strDateTime
     ElseIf (re4.Test(file.name)) Then
       strDateTime = re4.Replace(file.name, "$1")
       strDateTime = strDateTime & " " & reTime.Replace(file.modify, "$1:$2:$3")
       DOpus.OutputString "Date 4  = " & strDateTime
     End If
 
     If (Not IsEmpty(strDateTime)) Then
       DOpus.OutputString "New Date & Time: " & strDateTime
attrcmd = "SetAttr FILE=" & Q(file.path & file.name) & " MODIFIED=" & Q(strDateTime)
DOpus.OutputString attrcmd
ClickData.func.command.RunCommand attrcmd
     End If
'    End If      ' --- Uncomment to match "If file.is_dir Then" statement above
 Next
End Function
 
Function Q(s)
 Q = """" & s & """"
End Function