Rename then copy MOVE a file fails because windows still thinks file has old filename

Greetings Opi
Any help much appreciated.....

Script Action
With selected files this script
(1) Calls a rename internal command to add the suffix "SUFFIXX"; and then
(2) Calls a copy internal command to MOVE the file(s) to the destination alias "/work"

What Happens
See screenshot.
Script is executed with a single file selected (File001.png)
(1) rename call successfully adds suffix "SUFFIXX". This can be seen in the screenshot.
(2) copy MOVE call fails with a windows error shown. Windows as you can see is saying that the file cannot find the file filename "File001.png". This is because the file has been renamed.

Questions etc
What is going on? Strange thing is this script used to work.
Maybe some sort of flush operation might help?

Versions and Background
I have tried this with Opus64 12.21 and 12.31.
Reason I tried 12.21 is that it feels like and old issue that I have never gotten to the bottom of detailed here in this link. It seems like the reverse symptom somehow. The issue below did not happen with 12.21.
Lister not Refreshing and Explorer Replacement

function OnClick(clickData)
    DOpus.Output("001000 Start Rev_020T");
//  001000
//  001000 Start 017
//  001000

    var cmd = clickData.func.command
    CmdResult = cmd.RunCommand("rename PATTERN (.*) TO \"\\1 SUFFIXXX\" REGEXP IGNOREEXT");
	DOpus.Output("   004000-300b-140a Cmd No Result :" + CmdResult);
    CmdResult = cmd.RunCommand("copy MOVE to /Work");
	DOpus.Output("   004000-300b-140a Cmd No Result :" + CmdResult);

    DOpus.Output("005000 Process Dialog box RETURN END");

The script thinks it's still the old name for that is the data and variable it's working with. You need to update the name in the variable or make a new/different one for it, or add the name to the Copy command (adding a FILE argument).

Or move the file before renaming it.

Just add the destination folder to the Rename command:

cmd.RunCommand('Rename PATTERN=(.*) TO="/Work\\\\1 SUFFIXXX" REGEXP IGNOREEXT');

1 Like

Thanks @Pro Any idea how to do that?
I will probably go with @Ixp suggestion below but I am curious....

I see....this is the FILE switch from the copy commandL

@Ixp thanks. When I do that Opus create a subdirectory in the source folder and move the folder there instead of using the alias as intended. I have looked in the rename notes but I see no clarifying notes. Ideas?

Try replacing /work with {alias|work}.

Thanks @Ixp
I got some wierd results with the script see Test 10.
I ran the command via the FAYT prompt as you can see in Test 11 got something different again.
I really appreciate your help and I don't want to burn your time unnecessarily.
Let me retreat, take a break, and then check things out again.
I got help from @Leo a while ago with my Lister not refeshing issue mentioned above and I need to be more sure that it is not my end/my laptop etc. and is causing issues.
The thing that is in front of my mind is that my script has worked for many months/years maybe then started playing up. Symptoms vary alot and do not point in one direction. Below is another example of this. Not making sense at the moment.
Really really appreciate your help.


Ah yes... forgot something... {alias|work|escbackslash} should do it right.

I searched escbackslash and found a hit in Opus help page External control codes.
Is that what these things are?

Test 12 below with {alias|work|escbackslash} is the same result as Test 11.
At least I have consistency now.

So let us examine the (Test11/Test12) result.
The intention is to add a suffix.
The use of \1 in the Regular Expression is intended to act as a capture group referencing the original filename.
However this is being interpreted as a literal digit 1 as you can see below.
I tried removing one of the backslashes in the TO expression but no joy..

I use regex because it is powerful and I am used to it but at this stage I will take any solution :slight_smile:
BEFORE = Filename.ext
AFTER = Filename SUFFIX.ext

Ok... how about {alias|work|escregex}? Well, it probably won't work either.

Aliases and Regex probably won't mix well here :frowning:

I guess we need to either use a non-REGEX rename or switch to Copy MOVE.

I think this is solved. See below.
Fix on above is to add a space shown in what color is that? Light turquois?
I dropped it before troubleshooting.
Makes sense that it should be there.

What a mission. Thanks @Ixp - I was hopelessly lost... really really grateful.

Did not see this :slight_smile: before I posted.
A few closing questions if I may be so bold.

  1. The fix you gave me effectively adds a move function to the rename function.
    Is that documented there? I cant find anything
  2. The use of External Control Codes for passing filenames also... are "used to pass information like the names of selected files to external programs." Not strictly true then?

Either way really chuffed with this outcome it was crashing my life!! Thanks!!!!

Ad 1: Well, that's in Rename's DNA. You can completely change a file's path from Drive to Extension and all folders in between. Even if you only create a subfolder the file already gets not just renamed but moved as well.

Ad 2: Not true in the sense that it's only for external programs? I have never tried to insert a code like {allfilepath} into a rename statement, but it would probably work ...somehow :wink:

1 Like

Just when you thought it safe.
I have something close to a solution above thanks to great help from @Ixp
Question - Is it possible to add the ASK: feature so that the Select Destination Folder dialog, shown below, is brought up?
Or am I finally "asking" too much sorry terrible pun :slight_smile:


Like so?

Rename PATTERN=(.*) TO="{dlgfolder|Your choice!|/Work|escregex}\\1 SUFFIXXX" REGEXP IGNOREEXT

Thanks @Ixp. Unfortunately we have a windows error again.
I wonder if dlgfolder is passing the entire path? That might break things if so?

I think Lxp’s command is meant for the script. If you’re running it directly it won’t work because the backslash is escaped for JScript.

Looks like there’s also an extra space in your command before the backsashes.

(last edit?)

  • remove the space
  • add a p to escregex: escregexp
  • use 2 backslashes in a button, 4 in a script

I have got your string @Ixp to work in script and FAYT as per below.
Thank you so much I thought I was doomed to fail at the last hurdle!
Now I can fix my script.
My repeats of thank you seem inadequate somehow but I give them anyway!