Batch rename files with the folder name and sequence number - Send To Menu

孤人 提交于 2020-01-05 12:08:15

问题


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:


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


来源:https://stackoverflow.com/questions/21632266/batch-rename-files-with-the-folder-name-and-sequence-number-send-to-menu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!