Renaming a group of files, at the same time, using a regex to concatenate a number before their extension - Python or Batch Script
I want to rename each file that ends in .log, but I have similar files like:
x.log
x01.log
y.log
y01.log
....
I want to rename every file, at a time, with that extension (.*) but without any number, i.e., I want to rename x.log to xN.log, y.log to yNlog, z.log to zN.log, in which N is the number I want开发者_Go百科 to concatenate.
Is this possible in a Windows batch script using a regex or even Python?
Anything will do, as long as I can give the parameter N.
SET ext=.log
SET num=%1
FOR %%f IN (*%ext%) DO CALL :process "%%~nf"
GOTO :EOF
:process
SET name=%~1
SET lastchar=%name:~-1,1%
IF "%lastchar%" GEQ "0" IF "%lastchar%" LEQ "9" GOTO :EOF
RENAME "%name%%ext%" "%name%%num%%ext%"
精彩评论