Up front, vainly tried to get Filename to Modified Time.dcf working.
tried it on the examples at the bottom, selecting either one of the below and click on the toolbar button, but regretfully nothing happened.
I'd like to change modified date based on
either: -dd-mm-yyyy or -yyyy-mm-dd or ddmmyyyy
somewhere in the filename, like in filename-12-07-1973-kl03.JPG
no need to update the time.
preferrably as a preset.
(likely 3 presets will then be required ? as presumably a combination like (((\d{4}-\d{2}-\d{2}|\d{2}-\d{2}-\d{4}|((\d{2})(\d{2})(\d{4}))))) will not work?)
Maybe I misunderstand what you're trying to do so - apologies if that is true.
What I got from your post is that you want to use some kind of rename function, in order to parse a portion of the filename that may contain a date string in one of several possible formats... then use that date string from the filename in order to modify the files "Modified" date attribute?
If that is the case, then as MrC implied - you'll need a rename script that uses (most likely) regex rename capability to help parse that date string from the filename, then executes dopusrt.exe in order to run the SetAttr MODIFIED command. There's no way for the rename command alone to modify file properties...
Rename PATTERN="*" TO="*"
@script vbscript
Option Explicit
' 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/abusing-rename-scripts-to-do-other-things-with-file-info/5969/1
' 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")
Dim re1, re2
Set re1 = new RegExp
Set re2 = new RegExp
Function Rename_GetNewName(strFileName, strFilePath, fIsFolder, strOldName, ByRef strNewName)
Dim strYYYYMMDD
Dim strCommand
' Set strNewName to an empty string so that Opus does not rename the file.
strNewName = ""
re1.IgnoreCase = True
re1.Global = False
re2.IgnoreCase = True
re2.Global = False
' Test these date patterns: -dd-mm-yyyy or ddmmyyyy
re1.Pattern = "^(?:.*?)(?:-(\d{2})-(\d{2})-(\d{4})|(\d{2})(\d{2})(\d{4}))(?:.*)$"
' Test this date pattern: -yyyy-mm-dd
re2.Pattern = "^(?:.*?)-(\d{4}-\d{2}-\d{2})(?:.*)$"
If (re1.Test(strFileName)) Then
' Set strYYYYMMDD to a string like "2011-07-29"
strYYYYMMDD = re1.Replace(strFileName, "$3$2$1$6$5$4")
ElseIf (re2.Test(strFileName)) Then
' Set strYYYYMMDD to a string like "2011-07-29"
strYYYYMMDD = re2.Replace(strFileName, "$1")
End If
If (Not IsEmpty(strYYYYMMDD)) Then
'DOpus.OutputString "YYYYMMDD = " & strYYYYMMDD
strCommand = """" & DOpusRTPath & """ /cmd SetAttr FILE=""" & strFilePath & "\" & strFileName & """ MODIFIED=""" & strYYYYMMDD & """"
'DOpus.OutputString "CMD = " & strCommand
Shell.Run strCommand,0,true
End If
End Function
I think you must have put MrC's code into the wrong place, since the error you've got there is from the Rename command trying to rename a file, but the code MrC gave should never actually try to rename the file.
MrC's code is a button that should be pasted into the button editor. It won't work in the Rename dialog's script box, if that was where you were pasting it.
However, from testing the code, it works fine with your comp28-13-07-2014 13-02-14 apr.jpg example but doesn't work with your 016Lorem Ipsum - 01 - 19-04-1985-16-48-23.jpg example. In the second case, I get an error from the SetAttr command, I think because it's being passed an invalid date. Maybe the "- 01 - " before the date is confusing the regexp.
Yes, you are right, as always. I tried it in the normal 'rename' panel.
Changed Type: Standard Rename->Regular Expression, cleared the new name box, tagged script mode and pasted the code there.
(am not familiar with scripts and things)
Anyway, I did as you said, create button, etc.
Indeed the script seems to be stumbling over ' - ' or '- ## - ' stuff in front of the dates. It this isn't in the name the script is running well.
At least for the two examples I tried.
The seq# and dates are there to have series of screenshots in the right order.
(btw the spaces around the '-', hyphen, are in this case exceptional, in these 'test-names' as in the real filenames, I removed them all)
i.e. the actual filenames look like
Filename-11-19011983 164722.ext
Filename two-11-2013-06-03.ext
Filename three-11-19-04-2013 16-55-22.ext
or
in case of single files (i.e. no screenshot sequence)
they will look the same, but without the '-11' in the above examples, so
Filename three-19-04-2013 16-55-22.ext
Of course I prefer to have this in Opus .. Else I need to launch another tool, browse, click, click, select etc.
It is handier to have it in Opus.
I'm not sure if there's a question in the post, but all of your original file names work, as to the four "FIlename ..." files in the above post. So, are you good now, or do you have some file names that don't work?
It would be easy enough to deal with the space after the hyphen. I suppose some sanity checks could also check the modified date components too.
It helps others just to provide a list of those that don't work.
Lorem Ipsum - 01 - 19-04-1985-16-48-23.jpg
This - is - number - two-11 - 2013-06-03.jpg
Lorem Ipsum - 11 - 19011983 164722.jpg
but
as I removed all the spaces around the hyphen, the filenames to focus on are:
Lorem Ipsum-01-19-04-1985-16-48-23.jpg
Lorem Ipsum-01a-19-04-1985 16-48-23.jpg (note: no hyphen between date-time)
This-is-number-two-11-2013-06-03.jpg
This-is-number-two-2013-06-03.jpg (note: no seq#)
Lorem Ipsum-11-19011983 164722.jpg
probably it is too complicated to transfer the time?
i.e. in the first 3, time to be transferred too
in the 4th one (no time), then the exisiting time to be left untouched.
if it is too complicated, then time to be left untouched, that is fine as well.
right now time is reset to 00:00:00
So is it safe to say that your file name patterns look like:
STUFF
and that may or may not have a leading dash or space and in between year/month/day dashes or spaces, and is optional, but if it exists it must be 6 digits?
There's no reason to remove or convert the spaces ahead of time - the regular expression can manage this.
It sounds like you also want the modified time of the file to be read, so that when there is no time, the old time is retained.
(4) (\d{4})-(\d{2})-(\d{2})(?=\.)
This - is - number - two-11 - 2013-06-03.jpg
This-is-number-two-11-2013-06-03.jpg
This-is-number-two-2013-06-03.jpg (note: no seq#)
(5) (\d{2})-(\d{2})-(\d{4})[\s?\-?](\d{2})-(\d{2})-(\d{2})
Lorem Ipsum - 01 - 19-04-1985-16-48-23.jpg
Lorem Ipsum-01-19-04-1985-16-48-23.jpg
Lorem Ipsum-01a-19-04-1985 16-48-23.jpg (note: no hyphen between date-time)
I am no regexp - am trying to familiarize myself with regexp.
Maybe the above helps and saves some time, I don't know.
As for the script, tried to understand it , but gave up.
Rename PATTERN="*" TO="*"
@script vbscript
Option Explicit
' 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/abusing-rename-scripts-to-do-other-things-with-file-info/5969/1
' 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")
Dim re1, re2, re3
Set re1 = new RegExp
Set re2 = new RegExp
Set re3 = new RegExp
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 = ""
' Date / Time pattern: dd mm yyyy hh mm ss, with possible space or dash separators
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
re2.Pattern = "^(?:.*?)[-\s]*(\d{2})([-\s]*)(\d{2})\2(\d{4})(?:.*)$"
' Date pattern: -yyyy-mm-dd
re3.Pattern = "^^(?:.*?)[-\s]*(\d{4}([-\s]*)\d{2}\2\d{2})(?:.*)$"
If (re1.Test(strFileName)) Then
strDateTime = re1.Replace(strFileName, "$4$3$1 $5:$7:$8")
'DOpus.OutputString "Date Time = " & strDateTime
ElseIf (re2.Test(strFileName)) Then
strDateTime = re2.Replace(strFileName, "$4$3$1")
strDateTime = strDateTime & " " & GetFileModTime(strFilePath & "\" & strFileName)
'DOpus.OutputString "Date 1 = " & strDateTime
ElseIf (re3.Test(strFileName)) Then
strDateTime = re3.Replace(strFileName, "$1")
strDateTime = strDateTime & " " & GetFileModTime(strFilePath & "\" & strFileName)
'DOpus.OutputString "Date 2 = " & strDateTime
End If
If (Not IsEmpty(strDateTime)) Then
'DOpus.OutputString "Set Date & Time = " & strDateTime
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
I've used 3 RE patterns, as they are easier to work with and modify this way. Simpler is usually better. The first one looks for date / time combinations. The next two match date-only formats, in either of these formats: yyyymmdd or ddmmyyyy. In all REs, dashes or spaces can lead the date and/or time patterns, but must be consistent within the date and time patterns (eg. Good: dd-mm-yyyy or ddmmyyyy. Bad: dd-mm yyyy or hh-mm ss).
When no time is present, the file's current time is used; otherwise, the time from the file name is used.
001Lorem Ipsum-01-21042013 125022.jpg
002Lorem Ipsum-02-22042000-165132.jpg
003Lorem Ipsum - 03 - 23041970 174742.jpg
004Lorem Ipsum - 09 - 25042000 164852.jpg
005Lorem Ipsum - 26-04-1989 174852.jpg
006Lorem Ipsum - 28031998 174832.jpg
007Lorem Ipsum-07-31-01-1999 194832.jpg
008Lorem Ipsum-08-19-04-1999.jpg
009Lorem Ipsum-09-2011-03-01 134822.jpg *
010Lorem Ipsum-10-2012-04-01.jpg
--
This is great indeed!
Really perfect!
Personally, I donot mind the thing with file 009, time not being updated, so, as for me, you could leave it like this, it is already fine.
However, maybe others might wish to use this new script, or it could be converted to a .dcf ?
(a new " Filename to Modified Time.zip" ?)
in which case you may wish to correct that last small thing.
Here's your new version to handle case 9 (in the previous discussions, a time wasn't specified as being a requirement in the yyyymmdd format).
Rename PATTERN="*" TO="*"
@script vbscript
Option Explicit
' 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/abusing-rename-scripts-to-do-other-things-with-file-info/5969/1
' 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
' Set strNewName to an empty string so that Opus does not rename the file.
strNewName = ""
' 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})(?:.*)$"
If (re1.Test(strFileName)) Then
strDateTime = re1.Replace(strFileName, "$4$3$1 $5:$7:$8")
'DOpus.OutputString "Date 1 = " & strDateTime
ElseIf (re2.Test(strFileName)) Then
strDateTime = re2.Replace(strFileName, "$4$3$1")
strDateTime = strDateTime & " " & GetFileModTime(strFilePath & "\" & strFileName)
'DOpus.OutputString "Date 2 = " & strDateTime
ElseIf (re3.Test(strFileName)) Then
strDateTime = re3.Replace(strFileName, "$1 $3:$5:$6")
'DOpus.OutputString "Date 3 = " & strDateTime
ElseIf (re4.Test(strFileName)) Then
strDateTime = re4.Replace(strFileName, "$1")
strDateTime = strDateTime & " " & GetFileModTime(strFilePath & "\" & strFileName)
'DOpus.OutputString "Date 4 = " & strDateTime
End If
If (Not IsEmpty(strDateTime)) Then
'DOpus.OutputString "Set Date & Time = " & strDateTime
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