K
K
kristian3072019-11-22 10:59:52
cmd/bat
kristian307, 2019-11-22 10:59:52

How to write a script to rename files while keeping the extension?

Hello. Please help with writing a BAT script, because I myself am a complete zero in it.
Task. There are several files:
setup.exe
setup-1.bin
setup-2.bin
We need to rename them all to get
setup_ver1.0.exe
setup-1_ver1.0.bin
setup-2_ver1.0.bin
In short, at the end of the file name , add _ver1.0 before the extension. How can I do that?
I tried a bunch of options, like
ren "setup*" "setup*_ver-1.0.*"
And in a loop, nothing helped. Thanks in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
res2001, 2019-11-22
@res2001

@echo off
for %%a in (c:\temp\*) do (
  ren "%%~a" "%%~na_ver1.0%%~xa"
)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question