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

问题描述

这是我想要的,在 BACKUPDIR 里面,我想执行 cscript/nologo c:deletefile.vbs %BACKUPDIR% 直到文件夹内的文件数大于 21(countfiles 持有).这是我的代码:

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:	est
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%

这会将 countfiles 设置为 0.我认为您想将其减少 1,因此请改用它:

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

set /a countfiles-=1

我不确定 for 循环是否有效,最好尝试这样的操作:

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循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 17:04