Rename and copy

Hi!

I have been looking at the help to find this out. Basically i want to copy a file, leaving the extension intact, but rename filename with a rename preset script. Script, because i want yesterdays date in the filename. With buttonpress.

For example:
Original file: D:\data.xlsx
Copy that to C:\data_2020_0923.xlsx (yesterday)

Been using this script:

How can i achieve this? Thank you!

Try this. Are you sure you want everything copied to C:\?

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

    var currDate = DOpus.Create().Date();
    currDate.Sub(1, 'd');
    var dateStr = currDate.Format('D#yyyy_MMdd');

    for (var e = new Enumerator(tab.selected_files); !e.atEnd(); e.moveNext()) {
        var item = e.item();
        cmd.RunCommand('Copy FILE="' + item + '" AS="' + item.name_stem + '_' + dateStr + item.ext + '" TO="C:\\"');
    }
}

Copy Yesterday.dcf (1.2 KB)


Thanks very much Ixp! I will try this soon. Well, not C:\ exactly, but to the other lister, like a normal copy button.

Thought so... replace line 12 with this

cmd.RunCommand('Copy FILE="' + item + '" AS="' + item.name_stem + '_' + dateStr + item.ext + '"');
1 Like

Thank you @lxp for your time! Works great! I appreciate it!

So currDate.Sub(1, 'd'); subs 1, so if i do something like currDate.Add(1, 'd'); will it add 1? Will currDate.Sub(-1, 'd'); add 1?

Is there a simple way to enable this for drag-and-drop? Like in the filetypes editor - all files - drop menu? I thought if it works in a button then it should work with drag-drop. It also works in a right-click context menu.

Thx again, already using this a lot!

https://www.gpsoft.com.au/help/opus12/index.html#!Documents/Scripting/Date.htm

Should be possible via Settings > File Types > All Files and Folders > Drop Menu, assuming the aim is to access it for the right-mouse drag & drop menu.

Thanks!

Yes, right click drag and drop. It gives this error:

2020.09.26 15:52 Error at line 1, position 29
2020.09.26 15:52 function OnClick(clickData) {
2020.09.26 15:52 ^
2020.09.26 15:52 Invalid character (0x800a0408)
2020.09.26 15:52 Parse error - script aborted

I put the script straight into the button.

In a context menu you need to specify the script language on the top line of the script (it defaults to vbscript). Add @script jscript as the first line.

Thanks @Jon!

When i drag from the right to the left pane it doesnt do anything.
I can drag onto the tree, on a folder inside the folder where the file is, everything else works fine except from source to destination.