Copy File While Appending Date/Time Stamp

I'd like a function that copies selected file(s) to the same folder, appending date/time to the new filename. I want to keep the original file in addition to the copy. So, "test.txt" and "test 20150910 1014.txt" both show up in the same folder.

How would I accomplish this?


Quick Follow Up --

I found this link here - but it doesn't create a copy of the file before it renames it.

This command should do what you want:

Copy PATTERN *.* AS "* {date|yyyyMMdd} {time|HHmm}.*"

Please link your account if you need more detailed help.

1 Like

Thank you for your reply, Leo. And my account is now linked!!

What about modifying so it works with both directories and files. Also - the function only works on one file. Could it be changed so it works on whatever files/directories are selected?

Copy DUPLICATE WHENEXISTS=rename AS "{file|noext} {date|yyyyMMdd} {time|HHmm}{file|ext}"

seems to work on all selected files and folders.

There are a few ways to tackle that, but I went with this one which uses scripting to split things into two lists:

  • Files with extensions
  • Files without extensions, and folders (with or without dots in their names).

Set the Function drop-down to Script Function, and then Language to VBScript, and then use this as the code:

Function OnClick(ByRef clickData)
	Set vecWithExt    = DOpus.Create.Vector
	Set vecWithoutExt = DOpus.Create.Vector

	For Each item in clickData.Func.SourceTab.selected_dirs
		vecWithoutExt.push_back item

	For Each item in clickData.Func.SourceTab.selected_files
		If InStr(item, ".") Then
			vecWithExt.push_back item
			vecWithoutExt.push_back item
		End If

	If Not vecWithExt.Empty Then
		For Each item in vecWithExt
			clickData.Func.Command.AddFile item
		clickData.Func.Command.RunCommand "Copy PATTERN *.* AS ""* {date|yyyyMMdd} {time|HHmm}.*"""
	End If

	If Not vecWithoutExt.Empty Then
		For Each item in vecWithoutExt
			clickData.Func.Command.AddFile item
		clickData.Func.Command.RunCommand "Copy PATTERN * AS ""* {date|yyyyMMdd} {time|HHmm}"""
	End If
End Function

The two RunCommand lines near the bottom are the things you might want to change if you want different date formats or patterns. That part should be straightforward if you already understand how the old command worked, and the rest shouldn't need changing.

Thanks for linking, too!

Thank you Leo for taking the time to write such an elegant solution.

When I run function in dual panes it copies to the other pane. I'd like to copy to the same pane. I tried adding the word 'HERE' toe the RunCommand lines but that didn't work. What did I miss?

Use DUPLICATE e.g. Copy DUPLICATE PATTERN... with the rest as before.

1 Like