我确信这是显而易见的,但我似乎无法弄清楚,出于某种原因,我粘贴在下面的批处理文件总是运行两次而不是一次点击它:重命名。有人能告诉我这里的问题是什么吗?这与其他2个问题相关 - Looking for a way to execute a batch file once a folder hits 10 files和copy and rename files of a certain extension via batch file
这是批处理文件--->
rem Counting files...
set /a count = 0
for /f "tokens=*" %%P IN ('dir "H:\" /A /b') do (set /a count += 1)
rem 5 or more files?
if %count% GEQ 5 call :rename
:rename
SET count=1
FOR /f "tokens=*" %%G IN ('dir /b *.jpg') DO (call :rename_next "%%G")
goto:copy
:rename_next
ren "%1" %count%.jpg
Pause
set /a count+=1
goto:eof
:copy
xcopy c:\photo\*.jpg c:\photo\files /Y
Pause
答案 0 :(得分:0)
这一行:
if %count% GEQ 5 call :rename
正在调用:rename
。重命名返回后,代码会在此之后继续,如果恰好是:rename
。
替换为此代码以查看正在发生的事情:
echo before call
if %count% GEQ 5 call :rename
echo after call