Question

I have code that looks like this

%original%-added.txt

So if the original filename is

blue.txt

My code modifies that blue.txt file and the new file is then named

blue.txt-added.txt

How can I remove that first ".txt" so that I only get

blue-added.txt

Was it helpful?

Solution 2

Try like this :

%original:~0,-4%-added.txt

OTHER TIPS

Most likely a simple REN command is all you need. I'm assuming you always want to preserve the original file extension.

ren "%original%" "?????????????????????-added.*"

Just make sure there are at least as many ? as there are characters in the original name up until the .

Here are some results you can expect

original          new
--------          ------------
blue.txt          blue-added.txt
part1.part2.txt   part1-added.part2.txt

You could use wildcards in your source file mask. The following would append "-added" to the base name of all .txt files:

ren *.txt ?????????????????????-added.*

See How does the Windows RENAME command interpret wildcards? if you want to understand why this works.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top