Dulpicate with modified date

I would like to modify the AllFiles content menu to create an option to automatically duplicate a file. The new filename must be the old filename + the modified date of the file.
Ex. abc.txt last modified in 1/1/20013 20:10:10 to be renamed to abc 2013-01-01 20.10.10.txt

I have tried:

Rename PATTERN "(.).(.)" TO "\1 {modified|D#yyyy-MM-dd T#HH.mm.ss}.\2" REGEXP FILEINFO

...but after the first command the original file remains selected and renamed.

Any ideas suggestions?

Thank you in advance


I have the following in a context menu entry for All files and folders:

@nofilenamequoting Copy DUPLICATE WHENEXISTS=rename AS "{file|noext}_{date|yyyyMMdd}_{time|HHmmss}{file|ext}"

Everything from Copy to the end should be one line.

This creates a copy of the file or folder with a name involving the current date and time. Perhaps you could modify this to use the file/folder modified date/time instead.

Thank you for your reply I have one like yours but it does not work with {modified}


Yeah, I think it can be a bit confusing sometimes because some of the control codes like {modified} are not available to the Copy command. This as opposed to a code like {date} whose context is more system-wide and can be used in most every command. I think I'd requested some time ago that all control codes that are available with Rename FILEINFO be made available in the copy command as well... But as it stands, most (all?) of the file specific stuff that is usable in the Rename FILEINFO command is not broadly usable in other commands.

So unless I'm missing something obvious, it may be that the best way to do what you want is by Abusing Rename Scripts to do other things with file info like so:

[code]cd {s}
Rename FILEINFO TO "{file|noext} {modified|D#yyyy-MM-dd} {modified|T#HH.mm.ss}{file|ext}"
@script vbscript
Option Explicit

Function Rename_GetNewName(strFileName, strFilePath, fIsFolder, strOldName, ByRef strNewName)
Dim DEBUG, vbQuote, finfo, DOpusRTPath, commandLine, shell
' Change DEBUG flag to TRUE to debug without actually executing the commandLine
vbQuote = Chr(34)

' Take the {keywords} tag data sent in by strNewName, and store in local var
finfo = strNewName

' Set strNewName to an empty string so that Opus does not rename the file
strNewName = ""

' Change the path below if you haven't installed Opus to the default location:
DOpusRTPath = "C:\Program Files\GPSoftware\Directory Opus\dopusrt.exe"

' Build command line:
commandLine = vbQuote & DOpusRTPath & vbQuote & " /cmd " &_
"Copy DUPLICATE FILE " & vbQuote & strFilePath & "" & strFileName & vbQuote &_
" TO " & vbQuote & strFilePath & vbQuote &_
" AS " & vbQuote & finfo & vbQuote

' Create the req'd shell object needed to 'Run' the commandLine
Set shell = CreateObject("WScript.Shell")

' If debugging, look for messages in Opus by turning on Logs->Other Logs under the Help button on the default Menu toolbar
if DEBUG then
DOpus.OutputString "Command:" & vbCrLf & commandLine & vbCrLf
shell.Run commandLine,1,1
end if
End Function[/code]

Great!!!!! It works like charm!!!

Thank you very much!


Sure thing... and while I think this script does ~exactly what you wanted - in case you wanted to modify what it does, you can do so fairly easily even if you're not fluent with VBScript:

This part:

Rename FILEINFO TO "{file|noext} {modified|D#yyyy-MM-dd} {modified|T#HH.mm.ss}{file|ext}"

...is what sends the copied files new name to the script. If you ever want to change the format of copied files new name, you can do that almost entirely in this one line (unless you wanted to do some more elaborate processing of the new name in a way that isn't readily available using the Opus control codes).

This part:

commandLine = vbQuote & DOpusRTPath & vbQuote & " /cmd " &_ "Copy DUPLICATE FILE " & vbQuote & strFilePath & "\" & strFileName & vbQuote &_ " TO " & vbQuote & strFilePath & vbQuote &_ " AS " & vbQuote & finfo & vbQuote
...was written in the way it was mainly for readability, and is just a string variable to hold the dopusrt.exe command line (commandLine) that gets executed at the end of the script. If you wanted to make some modifications to the actual COPY command Opus runs as a result of the script, this is where you would do it. The command is broken up into 4 lines:

  1. the path to the dopusrt.exe : set in a variable (DOpusRTPath) earlier in the script - and which you would need to change if you install Opus to a different path
  2. the Copy DUPLICATE FILE portion of the actual command that will be run, along with the variables used by the script to specify the selected file(s) that is being copied
  3. the TO portion of the command that will be run, along with the path variable used by the script to set the target path (same as source path) for the copied file
  4. the AS portion of the command that will be run, along with the new file info (finfo) variable passed to the script from the Rename command to set the copied files new name

So... if you ever want to tweak it, you could make some changes to those areas and then preview the results of any changes simply by modifying the DEBUG = FALSE line to DEBUG = TRUE, and then opening the Script Output log to see the debug message that will show you the changes to the command line that the script generates. Turn the log on under the Help button on the default Menu toolbar:

Note: the "Other Logs" menu item opens the output window to the "Script Output" page...