GP SoftwareTwitter
Opus FAQsManualCommandsObjects

File name to modified date/time?

Hi.

I've been using some of the incredibly useful scripts & buttons. I've looked over the site and haven't found the answer (without learning the whole scripting thing which hasn't worked out).

I have bulk renamed a bunch of mp3's with AlbatorV's rename buttons scripts; e.g. 2011-07-29_082609.mp3

Having sorted out the poor levels in the audio, I would like to return the modified date to coincide with the file name also in bulk. Could someone help out with this (or point me to the solution if I missed it)?

Many thanks.

Do you want to change the file's modified date to match the one in the filename?

Or do you want to update the date in the filename to match the file's current modified date? (Wouldn't re-using AlbatorV's button do that?)

Hi, thanks for the reply. I have used AlbatorV's to modify the filenames. What I need to do now, having normalized the levels is return the modified dates to the original date & time. Regrettably the program which creates the files opens an mp3 then sits there with the file open until triggered by an audio event which it then records. As a result, the created date & time are mostly inconsistent with the actual time of the event, but the modified date & time is correct; well, minus the length of the clip!). Thus I am looking to take the file name and turn this back into the files modified date & time.

Here's a button which will do it:


Updated for 2017 / Directory Opus 12:

This uses proper scripting instead of kludging things through a rename script:

Script inside the button, for reference:

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 "2011-07-29_082609"
	re.Pattern = "^(\d\d\d\d-\d\d-\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 "2011-07-29 08:26:09"
			strDateTime = re.Replace(selItem.name_stem_m, "$1 $2:$3:$4")
			' DOpus.Output "DT  = " & strDateTime
			strCommand = "SetAttr FILE=""" & selItem.RealPath & """ MODIFIED=""" & strDateTime & """"
			' DOpus.Output "CMD = " & strCommand
			cmd.RunCommand strCommand
		End If
	Next
End Function

Original post for older versions of Opus:

Filename to Modified Time.zip (1.14 KB)

The button ignores any files that don't have names like 2011-07-29_082609.mp3 (the extension isn't important, but the rest of the name must be in that format).

It uses a regular expression to extract the date & time from the file, so that can be changed to make it work with other filename formats.

Installing the button:

  • Download the zip and extract it, so you have Filename to Modified Time.dcf. (Extracting it is important. Don't just double-click the zip to enter it.)
  • Enter Customize mode in Opus, via Settings -> Customize.
  • Drag the Filename to Modified Time.dcf file to your Opus toolbar and it will turn into a button.
  • (Optional) If Opus is not installed in the default location then you should right-click the newly created button, select Edit and change the DOpusRTPath line near the top.
  • Click OK in the Customize window to exit Customize mode.

(Here is a short video showing the steps above: nudel.dopus.com/posts/dcf_drop.wmv )

You can now select some files, click the button to set their timestamps (skipping any files whose names aren't in the expected format).

It doesn't recurse into directories, but you can make it do that if you want (just add the RECURSE argument to the Rename command at the top of the button).

Well, thank you very much, Sir! Do you ever stop working?? Whether you do or don't, one thing's for sure, I don't know how the hell I coped without DO all those years LOL.

Cheers, you're a star.

So... I'm back for my bi-annual nuisance visit!

Is there a way to have the rename script take a filename (YYYY-MM-DD_HHMMSS.mp3) and adjust the 'modified date' to the [file name] + [mp3 duration] ?

The example in question would be file(s) which have been 'date-named' and converted to a new format (e.g. WMA > mp3) thus losing their original modified date and time, which of course differs from the created ones.

I know, it's insane..... That's me tho.

I would like to use this button with the inverse operation, i.e. first store the date_time into the file name, but I can't find the inverse function of SetAttr.

The SetAttr command is for changing dates and attributes.

The Rename command is what you need if you want to change the filename. You can use the enable file information fields checkbox in the rename dialog (or FILEINFO argument if you're making a button to automate things) which then gives you a drop-down to insert codes, including ones for the file's dates and times.

See Renaming with Metadata for more information.

Indeed, thanks!

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.

Good luck!


Dear Leo et al,

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

Thank you!

Change these two lines to be like this:

...
	re.Pattern = "^(\d\d\d\d\d\d\d\d)_.*$"
...
			strDateTime = re.Replace(selItem.name_stem_m, "$1")
...

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

As expected, works smoothly! A last point, how the scripts may also set the TIME as 00:00:00?

Thank you.

Change "$1" to "$1 00:00:00"

Thank you very much dear Leo!

1 Like