Problem with Rename command

Hi,

I have an issue with Rename that is similar but not identical to the issue raised here:

https://resource.dopus.com/t/renaming-files-dont-rename-files-with-parentheses/33387

If I select the following files in the source window:

hello.txt
hello (there).txt
hello world.txt
hello1.txt

And I run a command button with this command on them:

Rename {f} TO {f|ext=pdg} WHENEXISTS=delete

I end up with these files:

hello.pdg
hello (there).pdg
hello world.txt
hello1.txt

Note that the first 2 files are renamed successfully but after the file with the parenthesis the renaming fails. Why is this so ?

This is a simplified example of what my overall button needs to do but this is the key problem. My button needs to work on flat view where files at many levels need to be renamed.

Regarding my topic (link above) - I'd also tried to rename in flat view mode and / or with filters (images = *.jpg, *.png) enabled - and it failed. I've forgotten to mention this.

Looks indeed a bit odd... After hitting one file with a parenthesis in the name the command only renames files with parentheses in them.

These files

ahello world.txt
bhello (there).txt
bhello (yeah).txt
hello1.txt
zhello (yeah) - Copy.txt

become

ahello world.pdg
bhello (there).pdg
bhello (yeah).pdg
hello1.txt
zhello (yeah) - Copy.pdg

Are you sure you need to use codes? Your example would work with this command:

Rename PATTERN=*.* TO=*.pdg
1 Like

I haven't checked in detail but I suspect using escwild may help things there:

Rename {f|escwild} TO {f|ext=pdg} WHENEXISTS=delete

That will prevent the ( characters being interpreted as wildcards.

That said, the command at the end of lxp's post, just above this one, is still better. You don't need to use {...} codes at all here, and the command will work better if you don't.

Unfortunately the {f|escwild} does not fix the issue.

The method suggested by lxp woks in this case, but my actual application is more complicated - I simplified the issue down here to minimise the amount of explanation and describe the problem as clearly as possible.

My button needs to decrypt thousands of password-protected pdfs that are in a large, deep hierarchical directory structure using the excellent qpdf tool. qpdf as a command line requires each individual file name to be passed to it and it cannot create any non-existing directories on output, nor can it overwrite the source pdf. As a result the best way to do it was to select the pdfs using Opus' flat view, which has the added benefit of being able to deselect specific files that need to be skipped. Here is the button code:

// Prompt for pdf password
Clipboard SET {dlgpassword|Enter PDF password|}
// Decrypt all selected files assuming they are only pdfs and create new file with pdf1 extension
qpdf.exe --password={clip} --decrypt {f} {f|ext=pdf1}
// Rename the decrypted files back to pdfs and overwrite the originals
Rename {f|ext=pdf1} TO {f} WHENEXISTS=delete
// Clear the clipboard
Clipboard SET

The reason lxp's suggestion wont work for the Rename line here is that the files that need to be renamed are no longer the selected files. I cant invert the selection as there are other files that can't be touched in the directories. I can't find a way that reselects the pdf1 files at all directory levels.

The code above works - until it hits a file with parenthesis in the filename. Any assistance greatly appreciated.

You can give the Rename command a FROM argument to tell it what to rename, and a PATTERN argument to tell it how to rename it. That should work.

Rename FROM {f|ext=pdf1|escwild} PATTERN *.pdf1 TO *.pdf WHENEXISTS=delete

(Converting the command to a script is another way to gain full control over which files each line runs on, but shouldn't be needed here.)

You can also avoid trashing your clipboard, while still only prompting for the password once, by setting a variable instead of using the clipboard:

// Prompt for pdf password
@set password={dlgpassword|Enter PDF password|}
// Decrypt all selected files assuming they are only pdfs and create new file with pdf1 extension
qpdf.exe --password={$password} --decrypt {f} {f|ext=pdf1}
// Rename the decrypted files back to pdfs and overwrite the originals
Rename FROM {f|ext=pdf1|escwild} PATTERN *.pdf1 TO *.pdf WHENEXISTS=delete

If the password might have a space in it, you'd probably want to put quotes around it, assuming qdpf.exe is OK with that:

...
qpdf.exe --password="{$password}" --decrypt {f} {f|ext=pdf1}
...

Or possibly like this (it may work both ways, but depends on the program):

...
qpdf.exe "--password={$password}" --decrypt {f} {f|ext=pdf1}
...

Of course, try on a few backup files first in case anything doesn't work as expected.

(Edit: I forgot the escwild which should still be there with the FROM argument.)

Thanks Leo, I tried your version of the Rename line but Rename throws an error "An error occurred renaming "Filename xxx.pdf1": The system cannot find the file specified". I'm not sure why it has failed on this particular file, and the file definitely still exists (verified while the error was still displayed using Windows explorer). The file in question is not at the top level of the directory structure, but it's hard to work out what order the files will be renamed in to know if it is the first file it is trying to rename or possibly the first not at top level, or possibly the first after a file with parenthesis in the name.

If I skip the error message the same error continues with every pdf1 file it is trying to rename. If I choose to skip all - Directory Opus crashes.

Please send us the Automatic crash logs (for bug reports) and we'll take a look.

Thanks - have emailed.

That crash is outside of our code. It seems to be happening in a Windows component (CoreMessaging.dll) which had a history of crashing in older versions of the OS, and several patches. Looks like you're on a year old version of Windows 10, which might be a factor.

Ok fair enough - now back to the parenthesis issue - how do we make the rename work in this case?

The dumps showed you're also using Opus 12.16.

12.17 from a month ago contained this fix:

  • Fixed codes like {file|noext|escwild} and {file|ext=*|escwild} removing/replacing the extension twice from names containing multiple dots.

That could be why it's not working for you. Please update and see if it solves things.

Updated to 12.17 - got the same error message of file not found on the rename as per my post above.

This has been fixed for the next update.

As a (very kludgy) workaround in the interim, it should work with the following command:

Rename {f} TO {f|ext=pdg} WHENEXISTS=delete FROMINLINE=0

1 Like

This is fixed in beta 12.17.4 now.

Many thanks Jon. It feels like so long ago we were selling opus to the Amiga community... come to think of it it was ... 28 years ago!!!

3 Likes