Copying and renaming a file, adding creation/modified date

Oops. I knew I should have asked :wink:

That copy-and-rename is indeed a bit trickier.

Try

// https://resource.dopus.com/t/copying-and-renaming-a-file-adding-creation-modified-date/47181

function OnClick(clickData) {
    var cmd = clickData.func.command;
    var tab = clickData.func.sourcetab;

    cmd.deselect = false;

    var dest = tab.path + '\\! bu';

    cmd.RunCommand('CreateFolder NAME="' + dest + '" READAUTO=dual,nofocus');
    cmd.SetDest(dest);

    for (var e = new Enumerator(tab.selected); !e.atEnd(); e.moveNext()) {
        var item = e.item();

        var cmdLine = 'Copy' +
            ' FILE="' + item + '"' +
            ' AS="' + item.modify.Format('D#yyyy.MM.dd, T#HH.mm.ss') + ' ' + item.name + '"' +
            ' WHENEXISTS=skip';

        // DOpus.Output(cmdLine);
        cmd.RunCommand(cmdLine);
    }
}
Button as XML
<?xml version="1.0"?>
<button backcol="none" display="label" hotkey_label="yes" label_pos="right" textcol="none">
	<label>47181</label>
	<tip>copying-and-renaming-a-file-adding-creation-modified-date</tip>
	<icon1>#script</icon1>
	<function type="script">
		<instruction>@script JScript</instruction>
		<instruction>// https://resource.dopus.com/t/copying-and-renaming-a-file-adding-creation-modified-date/47181</instruction>
		<instruction />
		<instruction>function OnClick(clickData) {</instruction>
		<instruction>    var cmd = clickData.func.command;</instruction>
		<instruction>    var tab = clickData.func.sourcetab;</instruction>
		<instruction />
		<instruction>    cmd.deselect = false;</instruction>
		<instruction />
		<instruction>    var dest = tab.path + &apos;\\! bu&apos;;</instruction>
		<instruction />
		<instruction>    cmd.RunCommand(&apos;CreateFolder NAME=&quot;&apos; + dest + &apos;&quot; READAUTO=dual,nofocus&apos;);</instruction>
		<instruction>    cmd.SetDest(dest);</instruction>
		<instruction />
		<instruction>    for (var e = new Enumerator(tab.selected); !e.atEnd(); e.moveNext()) {</instruction>
		<instruction>        var item = e.item();</instruction>
		<instruction />
		<instruction>        var cmdLine = &apos;Copy&apos; +</instruction>
		<instruction>            &apos; FILE=&quot;&apos; + item + &apos;&quot;&apos; +</instruction>
		<instruction>            &apos; AS=&quot;&apos; + item.modify.Format(&apos;D#yyyy.MM.dd, T#HH.mm.ss&apos;) + &apos; &apos; + item.name + &apos;&quot;&apos; +</instruction>
		<instruction>            &apos; WHENEXISTS=skip&apos;;</instruction>
		<instruction />
		<instruction>        // DOpus.Output(cmdLine);</instruction>
		<instruction>        cmd.RunCommand(cmdLine);</instruction>
		<instruction>    }</instruction>
		<instruction>}</instruction>
	</function>
</button>

How to use buttons and scripts from this forum

2 Likes