我有一个奇怪的情况,我不知道有什么问题
我需要检查目录中是否存在至少一个带模式的文件.
IF EXIST d:\*Backup*.* ( ECHO "file exist" ) ELSE ( ECHO "file not exist" )
如果在d:\我有一个文件x_Backup.txt
和一个文件夹Backup
我得到file exist
但是如果我只有文件夹Backup
我再次得到file exist
,似乎路径中的点被忽略.
还有一些未记录的通配符,您也可以使用它们来实现此目的.
IF EXIST "D:\*Backup*.<" ( ECHO "file exist" ) ELSE ( ECHO "file not exist" )
在以下两个链接中详细讨论了这个通配符选项和其他选项. 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
用这个; 它适用于任何特定模式:
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" )