vas*_*sor 6 windows cmd path batch-file filter
我有一个奇怪的情况,我不知道有什么问题
我需要检查目录中是否存在至少一个带模式的文件.
IF EXIST d:\*Backup*.* (
ECHO "file exist"
) ELSE (
ECHO "file not exist"
)
Run Code Online (Sandbox Code Playgroud)
如果在d:\我有一个文件x_Backup.txt和一个文件夹Backup我得到file exist但是如果我只有文件夹Backup我再次得到file exist,似乎路径中的点被忽略.
Squ*_*man 15
还有一些未记录的通配符,您也可以使用它们来实现此目的.
IF EXIST "D:\*Backup*.<" (
ECHO "file exist"
) ELSE (
ECHO "file not exist"
)
Run Code Online (Sandbox Code Playgroud)
在以下两个链接中详细讨论了这个通配符选项和其他选项. http://www.dostips.com/forum/viewtopic.php?t=6207
http://www.dostips.com/forum/viewtopic.php?f=3&t=5057
从这些链接:
The following wildcard characters can be used in the pattern string.
Wildcard character Meaning
* (asterisk)
Matches zero or more characters
? (question mark)
Matches a single character
"
Matches either a period or zero characters beyond the name string
>
Matches any single character or, upon encountering a period or end of name string, advances the expression to the end of the set of contiguous >
<
Matches zero or more characters until encountering and matching the final . in the name
Run Code Online (Sandbox Code Playgroud)
用这个; 它适用于任何特定模式:
set "fileExist="
for %%a in (d:\*Backup*.*) do set "fileExist=1" & goto continue
:continue
IF DEFINED fileExist (
ECHO "file exist"
) ELSE (
ECHO "file not exist"
)
Run Code Online (Sandbox Code Playgroud)
这是另一种选择。
dir d:\*back*.* /b /a-d >nul 2>&1
if errorlevel 1 echo files exist
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
27992 次 |
| 最近记录: |