With thanks to MrC, who has really done a great job in creating a script which may do most (if not all) what you need, you may wish to have a look at
thread: Change modified date after filename
specifically his last script, posted on 23 Aug 2013.
I admit, it is a bit of a tailor-made script and you need to test it first.
For example : your filename reads:
Filename 2011-07-29_082609.mp3
if you were to rename the filenames by removing the underscore (Filename 2011-07-29 082609.mp3), it will run just fine.
I have created a "Date from filename"-button to do the redates.
I have just tried your 2017 / Dopus 12 script and works fine with the filename format "YYYY-MM-DD_HH-MM-SS". I have even made a minor edit for changing the Creation Date attribute, instead of the Modified Date.
How this script can be modified for extracting the date from a format of "YYYYMMDD_" from either the filename OR from the folder-name? (two different scripts, on two buttons, are fine!)
This looks at the parent folder name instead of the file name:
Option Explicit
Function OnClick(ByRef clickData)
Dim strDateTime, strCommand, selItem, re, cmd
Set re = new RegExp
re.IgnoreCase = True
re.Global = False
' Folder name should be something like "20110729_anything"
re.Pattern = "^(\d\d\d\d\d\d\d\d)_.*$"
Set cmd = clickData.func.command
cmd.ClearFiles
For Each selItem in clickData.func.sourcetab.selected
If (re.Test(selItem.Path.filepart)) Then
' Set strDateTime to a string like "20110729"
strDateTime = re.Replace(selItem.Path.filepart, "$1")
' DOpus.Output "DT = " & strDateTime
strCommand = "SetAttr FILE=""" & selItem.RealPath & """ MODIFIED=""" & strDateTime & """"
' DOpus.Output "CMD = " & strCommand
cmd.RunCommand strCommand
End If
Next
End Function
(Change MODIFIED to CREATED as well if you want to set that timestamp instead.)
I just ran into the same issue. Since this topic is like 10 years old, do we have now some new moments? as Opus command set has significantly raised in power since...
I need to set the modified date from the first part of the filenames like this:
My locale date format is "dd.MM.yyyy" - I'm not sure how it would interfere with all that business?
Apart from 3 short posts in the middle, the whole thread is about setting timestamps from filenames, including the start of the thread and the new posts this week.
(There was a Rename command in the original, old solution, because that was a way to run scripts in the past, before there was more widespread scripting support. It wasn't really renaming anything though, and the newer solution doesn't need that method.)
I was able to modify the script to write to the Standard Properties 'Date Created' field using 'CREATED' in place of 'MODIFIED'.
Video dates are a big problem in my line of work, and often the correct date is only in a filename or folder name. Is there a command argument to write the date from the filename to the Movie Properties 'Release Date' field? I have used Graphic Converter (for Mac only) for this task, but am looking for a Windows/PC solution.
As well as changing the command it runs, I made it use selected_files instead of selected, so it doesn't try to do this to folders. Folders don't have a release date property, so it wouldn't make sense to try to handle them.
Option Explicit
Function OnClick(ByRef clickData)
Dim strDateTime, strCommand, selItem, re, cmd
Set re = new RegExp
re.IgnoreCase = True
re.Global = False
' File name should be something like "20110729_anything"
re.Pattern = "^(\d\d\d\d\d\d\d\d)_.*$"
Set cmd = clickData.func.command
cmd.ClearFiles
For Each selItem in clickData.func.sourcetab.selected_files
If (re.Test(selItem.Path.filepart)) Then
' Set strDateTime to a string like "20110729"
strDateTime = re.Replace(selItem.Path.filepart, "$1")
' DOpus.Output "DT = " & strDateTime
strCommand = "SetAttr FILE=""" & selItem.RealPath & """ META=""releasedate:" & strDateTime & """"
' DOpus.Output "CMD = " & strCommand
cmd.RunCommand strCommand
End If
Next
End Function
While I can't answer your question, I am very curious as to why you would want to rename any photos or videos by their Modified date? As a professional photo organizer, I would never do that because when the files are sorted by their Date Taken or Capture Date or Media Created Date (column name will depend on the application) the files will not sort by the date in the filename - unless that date happens to match the Date Taken or Capture Date or Media Created Date.
The first script uses a different name/date format, and I think the other script looks at the parent folder name rather than the file name.
This one should work (detail was above, but involved taking the first script and modifying two lines in it, which I've done here so it's all in one place):
Changes the date part, leaving the time part as whatever it currently is.
Affects all selected items (both files and folders).
Option Explicit
Function OnClick(ByRef clickData)
Dim strDateTime, strCommand, selItem, re, cmd
Set re = new RegExp
re.IgnoreCase = True
re.Global = False
' Name, ignoring extension, should be something like "20110729_Xyz"
re.Pattern = "^(\d\d\d\d\d\d\d\d)_.*$"
Set cmd = clickData.func.command
cmd.ClearFiles
For Each selItem in clickData.func.sourcetab.selected
If (re.Test(selItem.name_stem_m)) Then
' Set strDateTime to a string like "20110729"
strDateTime = re.Replace(selItem.name_stem_m, "$1")
' DOpus.Output "DT = " & strDateTime
strCommand = "SetAttr FILE=""" & selItem.RealPath & """ MODIFIED=""" & strDateTime & """"
' DOpus.Output "CMD = " & strCommand
cmd.RunCommand strCommand
End If
Next
End Function
Super.
Many thanks Leo! Matter solved.
(FWIW only, for my personal use I prefer the time be changed as well, hence I slightly updated the regex part to: "^(\d{8})(\s|_|-)(\d{6})$" and the replace to "$1 $3")
Anyway, thanks again.
Thanks. Yes I know. OTOH sometimes files do not have EXIF details (e.g. screenshots).
MP4 files no not have EXIF details either.
I believe the created date-time attributes are stored under QuickTime and in Opus file properties "Media Created". AFAIK, when changing attributes, there is no option to select 'Media Created' date-time stamp. Then again, this would only apply to MP4 files...
In case of other video filetypes (e.g. .mkv, wmv) it is more complex (=maybe impossible?) to get the original created date time stamp.