Batch rename files with the folder name and sequen

2019-08-10 11:49发布

I have a folder called sales. I have imgxy.jpg, imgab.jpg etc in that folder. When I right click the sales folder and send to rename.bat file (I have already copied the rename.bat file into c:\documents and settings\username\send To) I want the files in the sales folder to change to sales1.jpg, sales2.jpg etc. This behaviour should be true for anything I send to this .bat file. The following code was working properly on windows 7 last night. Now I am om windows xp sp3 and it doest work. It is trying to rename files in the folder *c:\documents and settings\username*

Please help rename.bat file code below

@ECHO OFF
setlocal enabledelayedexpansion
set foldername=%1
for %%i in (%bar%) do set bar=%%~ni
FOR /D  %%# in (%bar%) DO (
PUSHD "%%#"
FOR %%@ in ("*") DO (
    set /a "inc+=1"
    Echo Ren: ".\%%~n#\%%@" "%%~n#!inc!%%~x@"
    Ren "%%@" "%%~n#!inc!%%~x@"
)
POPD
)

1条回答
不美不萌又怎样
2楼-- · 2019-08-10 12:31

Test this - it accepts a folder, not files, but you mentioned folders in your question.

Don't call it rename.bat because rename is an internal command.

@ECHO OFF
setlocal enabledelayedexpansion
PUSHD "%~1"
set inc=0
FOR /f "delims=" %%a in ('dir /b /a-d') DO (
    set /a inc+=1
    Echo Ren: "%%a" "%~n1!inc!%%~xa"
    Ren "%%a" "%~n1!inc!%%~xa"
)
POPD
查看更多
登录 后发表回答