I am looking for a way to create a button that duplicates a file and then renames that file by replacing the year, month, and day parts.
So when this is the original file: Testfile - dd201005.txt
I would like to have a button that copies the file and renames the new file to: Testfile - dd211123.txt
The dd is a prefix, and the number is in yymmdd format.
When trying to create this, I first copied the file and then started with the rename window. I managed to trim the right part of the file and add the date code at the end. However, it seems I cannot get it to work all the way because the datestamp does not work. I have created a screencast where I show what I do and where things go wrong. Also, I show how the original preset does work.
Is there anyone who can help me to create a script that does the following:
The Copy command can rename files, but it is not as powerful as the Rename command. So we let a script take care of this. The button will work on all selected files.
// https: //resource.dopus.com/t/file-copy-trim-and-add-current-date/39902
function OnClick(clickData) {
var cmd = clickData.func.command;
var tab = clickData.func.sourcetab;
cmd.deselect = false;
// cmd.RunCommand('Set UTILITY=otherlog');
// DOpus.ClearOutput();
var currDate = DOpus.Create().Date().Format('D#yyMMdd');
for (var e = new Enumerator(tab.selected_files); !e.atEnd(); e.moveNext()) {
var item = e.item();
var cmdLine = 'Copy DUPLICATE AS="' + item.name_stem.replace(/\d\d\d\d\d\d$/, currDate) + item.ext + '"';
// DOpus.Output(cmdLine);
cmd.RunCommand(cmdLine);
}
}