Home > Software design >  file name contains string in batch
file name contains string in batch

Time:11-15

I want to rename 2 files and remove only number from their names. For example I have 2 files, localhost 3.pem and localhost 3-key.pem and I want to change them to localhost.pem and localhost-key.pem respectively.

So far I have came up with this script to find pem files in current directory but I don't know how to rename them to desired names.

@ECHO OFF
for %%f in (*.pem) do (
  echo %%f
)
PAUSE

I don't know, in advance, the number after in the file names

CodePudding user response:

if it's always a single digit number after the plus sign, then just try

rename "localhost ?.pem" localhost.pem
rename "localhost ?-key.pem" localhost-key.pem
  • Related