# Copy File While Appending Date/Time Stamp

**URL:** https://resource.dopus.com/t/copy-file-while-appending-date-time-stamp/21182
**Category:** Help & Support
**Created:** [September 10, 2015, 5:28pm UTC](https://resource.dopus.com/t/copy-file-while-appending-date-time-stamp/21182 "2015-09-10T17:28:11Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![timeblaze](https://resource.dopus.com/letter_avatar_proxy/v4/letter/t/a698b9/32.png) [@timeblaze](https://resource.dopus.com/u/timeblaze)
#### Post date: [September 10, 2015, 5:28pm UTC](https://resource.dopus.com/t/copy-file-while-appending-date-time-stamp/21182/1 "2015-09-10T17:28:11Z")

</div>

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?

Thanks!

---

<div class="post-metadata">

### Author: ![timeblaze](https://resource.dopus.com/letter_avatar_proxy/v4/letter/t/a698b9/32.png) [@timeblaze](https://resource.dopus.com/u/timeblaze)
#### Post date: [September 10, 2015, 5:40pm UTC](https://resource.dopus.com/t/copy-file-while-appending-date-time-stamp/21182/2 "2015-09-10T17:40:41Z")

</div>

Quick Follow Up --

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

> [@Add the current date and time to a file's name](https://resource.dopus.com/t/add-the-current-date-and-time-to-a-files-name/1328/1):
>
> Note: 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] &nbsp;&nbsp;…

---

<div class="post-metadata">

### Author: ![Leo](https://resource.dopus.com/user_avatar/resource.dopus.com/leo/32/69732_2.png) [@Leo](https://resource.dopus.com/u/Leo)
#### Post date: [September 10, 2015, 6:34pm UTC](https://resource.dopus.com/t/copy-file-while-appending-date-time-stamp/21182/3 "2015-09-10T18:34:32Z")

</div>

This command should do what you want:

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

Please [link your account](http://www.gpsoft.com.au/support/support-request.html) if you need more detailed help.

---

<div class="post-metadata">

### Author: ![timeblaze](https://resource.dopus.com/letter_avatar_proxy/v4/letter/t/a698b9/32.png) [@timeblaze](https://resource.dopus.com/u/timeblaze)
#### Post date: [September 10, 2015, 7:05pm UTC](https://resource.dopus.com/t/copy-file-while-appending-date-time-stamp/21182/4 "2015-09-10T19:05:05Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![rcoleman1943](https://resource.dopus.com/user_avatar/resource.dopus.com/rcoleman1943/32/38773_2.png) [@rcoleman1943](https://resource.dopus.com/u/rcoleman1943)
#### Post date: [September 10, 2015, 8:31pm UTC](https://resource.dopus.com/t/copy-file-while-appending-date-time-stamp/21182/5 "2015-09-10T20:31:15Z")

</div>

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

```

seems to work on all selected files and folders.

---

<div class="post-metadata">

### Author: ![Leo](https://resource.dopus.com/user_avatar/resource.dopus.com/leo/32/69732_2.png) [@Leo](https://resource.dopus.com/u/Leo)
#### Post date: [September 10, 2015, 8:39pm UTC](https://resource.dopus.com/t/copy-file-while-appending-date-time-stamp/21182/6 "2015-09-10T20:39:53Z")

</div>

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:

```vbscript
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
	Next

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

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

	If Not vecWithoutExt.Empty Then
		clickData.Func.Command.ClearFiles
		For Each item in vecWithoutExt
			clickData.Func.Command.AddFile item
		Next
		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!

---

<div class="post-metadata">

### Author: ![timeblaze](https://resource.dopus.com/letter_avatar_proxy/v4/letter/t/a698b9/32.png) [@timeblaze](https://resource.dopus.com/u/timeblaze)
#### Post date: [September 10, 2015, 9:39pm UTC](https://resource.dopus.com/t/copy-file-while-appending-date-time-stamp/21182/7 "2015-09-10T21:39:23Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![Leo](https://resource.dopus.com/user_avatar/resource.dopus.com/leo/32/69732_2.png) [@Leo](https://resource.dopus.com/u/Leo)
#### Post date: [September 10, 2015, 10:04pm UTC](https://resource.dopus.com/t/copy-file-while-appending-date-time-stamp/21182/8 "2015-09-10T22:04:40Z")

</div>

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