Replace characters


I guess this is trivial but I have now searched a long time and didn't find an answer.

From time to time I have a bunch of files whose names I want to rename. They have characters which I want to change to other characters. For example say I need to change every a to x, every b to y, every c to z and to remove every ! (exclamation mark).

How shall I do that?

I use a button for this which prompts me for the text to find and replace:

<?xml version="1.0"?> <button display="label" effect="gray"> <label>Replace</label> <icon1>84</icon1> <function type="normal"> <instruction>rename PATTERN="{dlgstring|Find in filename:}" TO="{dlgstring|Replace with:}" FINDREP</instruction> </function> </button>

To remove characters I have a specific "Strip Characters" button:

<?xml version="1.0"?> <button display="label" effect="gray" separate="yes"> <label>Strip Characters</label> <icon1>84</icon1> <function type="normal"> <instruction> rename pattern "{dlgstring}" to \~ findrep</instruction> </function> </button>

You can do this from the Rename dialog as well. Put it in advaned mode and then in Find and Replace mode. Which method is best depends on exactly how you use it.

Thank you for your answers!

As I have no previous experience of Directory Opus I wonder if you could please show me exactly how I will enter the command in the Find and Replace fields, in the Rename dialog window. I find out how I can change one character at a time but I hope there is someway to change all at once.

I think the manual is not helpful with explaining how the rename works.

You select Find and Replace mode and then put the string you want to find in the first text box and what you want to replace it with in the second. The preview list below shows you what will happen to the filenames.

(Make sure you are in Advanced mode in the rename dialog.)


but I hoped there could be a way to change every a, b and c to x, y and z at once. Now I have to first change a, then b and last c.

I don't know of a reliable way to do that at the moment.

However, if you are often making the same changes to files then you can create some buttons which do each change and can then be clicked in sequence.

For example, I have a three-button which I middle-click and then right-click in order to replace underscores with spaces and then capitalise each word.

If it's not always the same things then the first button Tanis posted gives you a quick way to specify before and after strings each time.

So it is not possible to create just one button that does all changes at once?

You must realize that what you want to do is actually three separate Find-and-Replace renames in a queue. So no, a single RegExp command cannot facilitate that.

It still may be possible to put all three Find-and-Replace Rename commands into a single Opus button. However, it is not really safe for renaming more than a single file at a time (and depending on how complex your RegExp is, it may not even be reliable for a single file).

There are timing issues with:[ul][li] The time it takes hard drive to write the new file name after each rename step executes and report it to Windows.[/li]
[li] The time it takes Windows to update the file names and make it available to Opus[/li]
[li] The time it takes Opus to update its file listing.[/li][/ul] Opus executes a Rename command based on the current file name in its listing. However, Opus fires off its commands very quickly. Opus does provide this convention to synchronize the start of a commands:

Sync: dopusrt /cmd Rename <parameters>

However, this convention does nothing to synchronize the start of one rename command with the completed results of the previous Rename command (that is, the updated file listing). So if the Opus file listing isn't updated quickly enough between rename steps, there will be errors. This is called a "race condition".

I've been working on a toolbar with several Format Renames (multi-step renames that take a file from one file name format to another file name format). I have some format renames that have as many as 16 different RegExp Rename commands to complete the Format Rename. I have come up with some techniques that help in these circumstances, but I'm not done stress-testing them yet.

Even still, I can help you create a button that can safely rename a single file. But, I strongly advise against using it on more than one file at a time, as you will get errors.

I am also drafting a Feature Request to submit to GPSoftware for an enhancement that could nullify the timing issues. The idea is still a work in progress though so it will be some time before I submit the request.

Before I can really help you, you should post some Before-And-After examples of files that you wish to rename and the rename rules that you would like to apply to them. Without that I can't really help you much.

Issue: KA#00040 - Request Multi-Step Rename Queue with raw command support
Status: Analysis

Thanks for a very detailed and interesting answer.

[quote]Even still, I can help you create a button that can safely rename a single file. But, I strongly advise against using it on more than one file at a time, as you will get errors.
My need is to rename groups of filenames. It's ok to do it with three buttons. I just wanted to know if it could be done with just one.

Thank you for your offer but it is not that important for me.

Here's what each button's command should be like:


The @NODESELECT means the files will stay selected and ready for the next button to be pushed.

I have now made seven buttons to do what I wanted and it works great. A very impressive program.

Thanks to you all who have answered!

If regular expressions can be used to catch different strings like a|b|c as in the manual example, could one create a command for the following?

replace pattern="a|b|c|" TO=" " FINDREP

and thereby turn all As Bs and Cs into spaces?

Would that work? I'm trying to do it in the rename popup, but either find and replace works, or regular expressions do, but not at the same time. Grrr.

"Find and Replace" and "Regular Expressions" are two distinct ways to rename files. You cannot combine the two and it doesn't make any sense to combine the two since they work in different ways.

What you want is a regular expression rename from



\1 \3

The \1 and \3 in the to-string are replaced by whatever matches the first and third things in brackets, which are both .* expressions which match anything. The middle thing brackets matches your a|b|c and is turned into a space.

The # at the end tells Opus to keep applying the expression until the result doesn't change anymore and without that you'd only replace one a, b or c with a space and leave the rest.

That was EXACTLY what I was looking for. Thank you so much. I knew DO could do it!

I took the time to really understand what you were saying instead of just cutting and pasting. So thanks for explaining it.

One more question if you don't mind - Is there a way to create a button that would run several other buttons in sequence? If so, could one program a time delay between? That could really build off of what I've just learned.

This could handle repetitive commands like: replace|all|unwanted|characters, sort by name, capitalize all, and number by date--all in one click

Possible? Thanks!

Many of us are waiting for the capability to do the same thing in Opus. :wink: