批量使用For循环中的If条件 [英] Using If condition in For loop in batch
本文介绍了批量使用For循环中的If条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
截至目前,我使用如下所示的批处理执行操作.(/*)DO命令中的FOR/D %% G
As of now i perform a operation using batch like below. FOR /D %%G in ("*") DO command
- 这在所有文件夹上执行该命令,因为我已使用"*"标记,现在我需要跳过上述命令中的文件夹(名称为* Shared).
请告知我是否可以使用IF循环执行相同的操作以及如何执行操作.或建议是否有任何简单的执行方式
Please advice if i can use a IF loop to perform the same and how do i do. or suggest if there are any simple way to perform
推荐答案
您可以检查 %% G
变量以查看文件夹名称是什么.从那里,您可以获取最后6个字符,并查看该值是否为 Shared
.
You can check the %%G
variable to see what the folder name is. From there, you can get the last 6 characters and see if the value is Shared
.
我们使用 SETLOCAL ENABLEDELAYEDEXPANSION
,以便我们可以在循环内更新变量.
We use SETLOCAL ENABLEDELAYEDEXPANSION
so that we can update variables inside the loop.
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
FOR /D %%G in ("*") DO (
SET str=%%G
IF /I "!str:~-6!" NEQ "Shared" (
Command
)
)
PAUSE
这篇关于批量使用For循环中的If条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文