Add the current date and time to a file's name


  • The default toolbars now include commands which are the same or very similar to the ones in this thread, for Directory Opus 11 and above.

    You can find them in the menus attached to the Rename and New Folder buttons:

    200dpi_wc10310_dopus        200dpi_wc10311_dopus

Summary: The rename and create-folder functions in Directory Opus are able to include the current date and time in the names they create.

If you've got a file, say one with a generic filename or one that's a backup you just made of a directory, then you might want to rename it to something unique which also captures the current date and/or time. You may also want to make a quick temporary directory using the current date without having to think of a unique name. You can make toolbar buttons (or hotkeys) in Opus which do these things in a single click.

This examples below show how to make buttons which do particular rename operations in a single click. You could also do the same operations via the Rename dialog. It is also possible to make buttons which invoke saved Rename presets in a single-click. In the example below, though, the patterns are defined directly in the buttons and no rename presets are used. Doing it this way means that you don't have to have unwanted extra entries in your Rename presets list.

With Opus in Customize mode, if you copy the button definitions below (separately) to the clipboard and then right-click an empty area of one of your toolbars then you should get a Paste option which will add the button from the clipboard to your toolbar.

This first button creates a new directory which is named after the current date and time:

<?xml version="1.0"?>
<button display="both" effect="gray">
	<label>Create Dated Folder</label>
	<function type="normal">
		<instruction>CreateFolder NAME="{date|yyyy-MM-dd} {time|HH-mm-ss}"</instruction>

This second button will rename all of the selected files and directories by adding the date and time after their filenames. Its function body is two lines long because the first line handles the directories while the second line handles the files (making sure to add the date before the file's extension):

<?xml version="1.0"?>
<button display="both" effect="gray">
	<label>Date-Suffix Selected Names</label>
	<function type="normal">
		<instruction>Rename PATTERN="*" TO="* - {date|yyyy-MM-dd} {time|HH-mm-ss}" AUTORENAME TYPE=dirs</instruction>
		<instruction>Rename PATTERN="*.*" TO="* - {date|yyyy-MM-dd} {time|HH-mm-ss}.*" AUTORENAME TYPE=files</instruction>

In both cases you can edit the {date|...} and {time|...} parts of the button to alter the format of the date and time and, of course, you can remove either of them completely if you want.

Opus 12 and above: The second button could be done better, using a single line which handles both files and folders, using the new Ignore Extension rename feature. In fact, this improved version is provided for you within the default configuration, as mentioned at the top of the post.

You can also do the same kind of rename using a Rename Preset as shown below, instead of creating a button.

Before Opus 12: Don't forget to turn on the "enable file information fields" checkbox, else the {date} and {time} codes won't work. (This is done automatically from Opus 12 onward.)

Thanks for this. Both these button/scripts will be very useful for me.

Hi Leo;

Can you provide modified versions of these buttons that add the date to the start of the folder in this format 2015.11.07? Maybe adding the time could also could be made optional.

Kind regards, Mark

See Codes for date and time.