Find and Replace via button in filename extension

Hello,

How do I modify the following script so that it will only modify the .ext part of the file name? Right now, if I only search for one character it will replace it with the new one but it will also do it in the file name. For example:

Original
File Name.ext
File Name.ext

New (with file name also changed)
Fil5 Nam5.xt5
Fil5 Nam5.ex5

And what I need is (only extension changed):
File Name.xt5
File Name.ex5

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

How do I make the script stay only with the extension?

Try this regular expression button.
Enter the new extension in the dialog .

<?xml version="1.0"?>
<button display="label">
	<label>Replace Text in Extension</label>
	<icon1>84</icon1>
	<function type="normal">
		<instruction>rename PATTERN=&quot;(.*\.)(.*$)&quot; TO=\1&quot;{dlgstring|Enter new filename extension without . (period)}&quot; REGEXP</instruction>
	</function>
</button>

David,

Thanks. It works really great. I will keep it and add it to Dopus as another option.

However, I need one where it will find what I am looking for and then replace it by the new string.

I have many files which extension have say _ but some of them have at the beginning, others in the middle, others at the end. Therefore, I need the script to look for the specific string(s) and then change only that in place, find-and-replace.

But your script will replace the entire extension and that is awesome when all of them have the same extension. I love it, thanks.

How would I get it to find and replace only in the extension, two steps, first step it should ask me the string to look for, the second step what to replace it with.

Thanks David.

As I understand things, that would be much more difficult .

Yes, it could be done, but it is definitely something at least as I know tonight, that requires some custom work.
It is a definite maybe, but things can go wrong that seem easy at first glance.

Unless I'm wrong and someone else solves this easily

Try this one. It uses the evaluator function "Replace" to perform find and replace.
Rename TO="{{=Stem(file_name)=}.{{=Replace(ext, ""{dlgstring|Find in extension:}"", ""{dlgstring|Replace with:}"")=}"

2 Likes

Ahhh... a815, thanks... that did it.

Here is the final working code:

<?xml version="1.0"?>
<button display="label">
	<label>Replace Text in Extension</label>
	<icon1>84</icon1>
	<function type="normal">
		<instruction>Rename TO="{{=Stem(file_name)=}.{{=Replace(ext, ""{dlgstring|Find in extension:}"",  ""{dlgstring|Replace with:}"")=}"</instruction>
	</function>
</button>
1 Like