while循环批处理 [英] while loop in batch

查看:1353
本文介绍了while循环批处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好
这里是我想要的东西,里面的 BACKUPDIR ,我想执行 CSCRIPT / NOLOGO C:\\ deletefile.vbs%BACKUPDIR%,直到文件夹中的文件数量大于21( countfiles 持有它)。
这里是我的code:

 关闭@echo
SET BACKUPDIR = C:\\测试
FOR / F %%倍In('DIR%BACKUPDIR%/ B ^ |找到/ V / C::')做一套countfiles = %%点¯x针对%countfiles%GTR 21(
CSCRIPT / NOLOGO C:\\ deletefile.vbs%BACKUPDIR%
集/ A countfiles - =%countfiles%


解决方案

 设置/一countfiles  -  =%countfiles%

这将设置countfiles为0。我想你想通过1下降,所以用这个来代替:

 设置/一countfiles- = 1

我不知道,如果for循环将工作,更​​好地尝试这样的事情:

 :循环
CSCRIPT / NOLOGO C:\\ deletefile.vbs%BACKUPDIR%
集/ A countfiles- = 1
如果%countfiles%GTR 21页转到循环

Hello Here is what I want, inside the BACKUPDIR, I want to execute cscript /nologo c:\deletefile.vbs %BACKUPDIR% until number of files inside the folder is greater than 21(countfiles holds it). Here is my code:

@echo off
SET BACKUPDIR=C:\test
for /f %%x in ('dir %BACKUPDIR% /b ^| find /v /c "::"') do set countfiles=%%x

for %countfiles% GTR 21 (
cscript /nologo c:\deletefile.vbs %BACKUPDIR%
set /a countfiles-=%countfiles%
)

解决方案

set /a countfiles-=%countfiles%

This will set countfiles to 0. I think you want to decrease it by 1, so use this instead:

set /a countfiles-=1

I'm not sure if the for loop will work, better try something like this:

:loop
cscript /nologo c:\deletefile.vbs %BACKUPDIR%
set /a countfiles-=1
if %countfiles% GTR 21 goto loop

这篇关于while循环批处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆