我想做的是在目录中搜索包含.NA
的任何子文件夹。
Example Folder1 Folder2 Folder3.NA
只要有一个文件夹,.NA
什么都不做。当不再有任何文件夹包含.NA
删除其他文件夹中的文件时。
每次运行此代码时,我都不会进入:NotFound
部分来执行删除文件。
也许有人的解决方案与我的想法不同。
这是我的代码 - 这将在启动时运行:
@echo off
setlocal enabledelayedexpansion
Set Source=C:TempUsers
FOR /d %%a in ("%Source%*.NA") DO (
IF NOT !ErrorLevel! == 0 GOTO NotFound
IF !ErrorLevel! == 0 GOTO Found REM - There is still a user folder with .NA
)
Goto EOF
:Found
@echo There is a folder with .NA Do Nothing
Goto EOF
:NotFound
@echo Simulate delete start-up file
Goto EOF
:EOF
PAUSE
将 aschipfl 和我的建议放入代码中:
@echo off
setlocal enabledelayedexpansion
Set Source=C:TempUsers
FOR /d %%a in ("%Source%*.NA") DO Goto :Found
::fall through with no find
@echo Simulate delete start-up file
Goto :End
:Found
@echo There is a folder with .NA Do Nothing
:End
PAUSE
如果你需要一个带有暂停命令的自己的退出点,不要称它为 eof,这是一个内部自动标签。