首页 > 解决方案 > 该文件已用批处理文件重命名,但不会停止

问题描述

我需要通过在文件名前添加“BV”来重命名文件夹中的所有文件。我的代码正在运行,但是当该文件夹中的文件总量超过 ca. 200 个文件。它将所有文件重命名为:“BV_BV_BV ...”并且它不会停止。

这是我的代码:

@echo off & setlocal

ECHO Moechten Sie das wirklich tun? (Bereits vorhandene Bildverzeichnisse werden geloescht 
ECHO und in den Dateinamen wird AWK2 hinzugefuegt) (j / n)
SET /p wahl=
if '%wahl%' == 'n' goto Nein
if '%wahl%' == 'j' goto Ja

:Ja
ECHO on

FOR %%I IN (*.bmp) DO ren "%%I" BV_"%%~nI".bmp

pause

我不确定如何在重命名所有文件后停止批处理文件。谢谢你的帮助。

标签: batch-filefile-rename

解决方案


假设您想重命名所有文件一次,前缀为循环BV_中的示例。for注意,我用choice而不是set /p

@echo off & setlocal

ECHO Moechten Sie das wirklich tun? (Bereits vorhandene Bildverzeichnisse werden geloescht 
ECHO und in den Dateinamen wird AWK2 hinzugefuegt) (j / n)
choice /c jn /m "wahl"
goto opt%errorlevel%

:opt1
for /f "delims=" %%I IN ('dir /b /a-d *.bmp ^| findstr /v /b "BV_"') do ren "%%~I" "BV_%%~I"
goto :eof
:opt2
echo do what ever you need to do here.

推荐阅读