试图找出批处理文件运行两次的原因
我确信这是显而易见的,但我似乎无法弄清楚,出于某种原因,我在下面粘贴的批处理文件在点击:重命名时总是运行两次而不是一次。有人可以告诉我这里的问题是什么吗?这与其他两个问题有关 - 寻找一种在文件夹达到 10 个文件后执行批处理文件的方法 和 通过批处理文件复制并重命名某个扩展名的文件
这是批处理文件 --- >
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
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 "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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这一行:
正在调用
:rename
。 rename 返回后,代码在此 if 后继续,恰好又是:rename
。替换为以下代码以查看发生了什么:
This line:
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: