开发者

Trying to figure out why batch file is running twice

i am sure this is something obvious, but i cant seem to figure it out, for some reason, the batch file i have pasted below always runs twice instead of once when it hits :rename. Could someone tell me what the issue here is? This is related to the 2 other questions - Looking for a way to execute a batch file once a folder hits 10 files and copy and rename files of a certain extension via batch file

Here is the batch file --- >

rem Counting files...
set /a count = 0
for /f "tokens=*" %%P IN ('dir开发者_Go百科 "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


This line:

if %count% GEQ 5 call :rename

is calling :rename. After rename returns, the code continues after this if, which happens to be :rename again.

Replace with this code to see what's happening:

echo before call
if %count% GEQ 5 call :rename
echo after call
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜