File name to modified date/time?

Nevertheless, the script has worked flawlessly in my case. Thanks @Leo, appreciate it. :slight_smile:

1 Like

I see that the SetAttr internal commands are used in this script https://www.gpsoft.com.au/help/opus12/index.html#!Documents/SetAttr.htm

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.

:warning: This is not tested, so try it on some backup video files first in case I got something wrong.

This type of command should set the release date field on file types Opus knows how to do so:

SetAttr FILE="<filepath>" META="releasedate:<YYYYMMDD>"

Below is the altered version of the old script.

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

Thank you. Wonderful. It worked on MP4 files.

Please allow me to revert on this subject: one way or the other the script does not work. That is to say, nothing happens at -my- side.

I tried both the .dcf (at the top) and the script here at the bottom.

Filename is: (e.g.)
20221023_173910.jpg
20200423_134740.mp4

and I want to have the modified date to read as per the file name.

Any suggestions?

Thanks!

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):

  • Filename to Modified Time.dcf (1.9 KB)
  • Expected name/date format: YYYYMMDD_*
  • Works on filename (not parent folder name).
  • Changes Modified timestamp.
  • 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.