1

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

Jeremy Rowler
  • 387
  • 1
  • 5
  • 15

2 Answers2

2

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.

Community
  • 1
  • 1
dbenham
  • 127,446
  • 28
  • 251
  • 390
1

Try like this :

%original:~0,-4%-added.txt
SachaDee
  • 9,245
  • 3
  • 23
  • 33