Rename files recursive by wildcard / regexp

Maybe this is already in there somewhere, but I just want a simple feature that looks for all the *.txt files in the current folder and recursive folders and rename them by regexp or just *.txtBAK. I don't want to have to select each file, even though the flat view is handy for that.

A simple version of this this is easy in bash and looks like this:

find -iname "*.txt" -exec mv '{}' '{}BAK' ;

Use the RECURSE argument:

Rename FROM=*.txt TO=*.txtBAK RECURSE

Rename

But if I don't choose a file the Rename button is disabled, and if I choose a file it seems to work on only that file. I'm confused. I thought that the preview pane should show what it files it is going to rename but it doesn't when using wildcards like '*.txt'.

If you want this to work on selected folders instead of the source, use

Rename FROM={filepath}*.txt TO=*.txtBAK RECURSE

If you want the preview, add ADVANCED:

Rename FROM={filepath}*.txt TO=*.txtBAK RECURSE ADVANCED

I right click on the toolbar and choose Customize, then right click the Rename button and choose edit. If I add what you suggested the rename doesn't do anything, no error, just nothing. Am I digging too deep here maybe :slight_smile: ? What I'm trying to do is exactly what the bash command above shows, it's very simple.

So the original there is:
@disablenosel
@nodeselect

=return("Rename " + ($glob:dopus_Rename_Simple ? "SIMPLE" : "ADVANCED"))

Are you talking about somewhere else to add what you just wrote?

I'd make a new button. Here's mine:

XML
<?xml version="1.0"?>
<button backcol="none" display="both" label_pos="right" textcol="none">
	<label>59600</label>
	<icon1>#newcommand</icon1>
	<function type="normal">
		<instruction>// Rename FROM=*.txt TO=*.txtBAK RECURSE</instruction>
		<instruction>Rename FROM={filepath}*.txt TO=*.txtBAK RECURSE ADVANCED</instruction>
	</function>
</button>

How to use buttons and scripts from this forum

Since the filepath is provided, the RECURSE option has no effect: from a quick test, this is not operating on the .txt files in subfolders.

The initial Rename FROM=*.txt TO=*.txtBAK RECURSE works ... but requires (at least here) that something is selected in the sourcepath, otherwise the button is not active (even if there is no @disablenosel).

EDIT: Can't reproduce anymore the need to have something selected.

Where are you typing that code? In the Macro field of the Rename popup window?

I'm not trying to do anything dramatic or complex here, just stand in a folder and pick up, recursively, all *.txt files and rename them to *.txtBAK. And I would hope to make this with other renames without having to write a separate script or/and button.

This code goes directly in a button. This is what prevents you from using the Rename dialog.
You can call a Rename action without having to open the dialog if the action is properly defined in your call.

The XML code provided by lxp can be copied in the clipboard and pasted in a toolbar when in "Customize mode" (as described in the link provided below the xml code). This will create a button.

It starts to feel like a feature request, if I choose a folder in the File Explorer side without choosing any file and click rename, it should just start from there and find all the files using wildcards or regexp and rename them. And if I check the box "Rename in subfolders" it should just do that.

And I like generic solutions, not a script per purpose. Total Commander does this nicely with regexp, even though a bit complicated it works really well.

I do this type of think often without a script /command.

  • I select the parent folder and open it in Flat View (Mixed) No folders.
  • Then I use the Filter bar to select the file extension. In your case, the .txt extension.
  • I select the files displayed.
  • I open the Rename dialog.
  • Then I use whatever Rename option, like Regex, suits how I want to rename.

I think OP knows this can be done that way, see. :

You can also go up a level, select the directory, click Rename and turn on Rename files in selected sub-folders.

Yes, but he may not have known about the Filter Bar, which is not in the Default Configuration, as they seems to be a new user.

I often add detail to help other people with a similar question.

I just want to say that Directory Opus is by far the best file manager/explorer I've ever seen. I'm kind of nitpicking with this. Keep up the good job, and I will read the documentation.

I have one nut to crack though, where do I find the error output in a case where I click on a button and nothing happens?