考虑这个例子的VBScript片段:为什么FileExists不支持通配符?
Dim fs
Set fs = CreateObject("Scripting.FileSystemObject")
If fs.FileExists("D:\Folder\File*.ext") Then ' Finds nothing!
fs.CopyFile "D:\Folder\File*.ext", "D:\OtherFolder\"
fs.Deletefile "D:\Folder\File*.ext"
End If
的FileExists
方法证明不是支持通配符(*
和?
)。不是FolderExists
。我预计wildards只是工作,因为他们工作的优良在FileSystemObject
所有类似的方法:CopyFile
,CopyFolder
,MoveFile
,MoveFolder
,DeleteFile
,DeleteFolder
和Get*
文件名处理方法一样GetAbsolutePathName
。
当然有办法解决这个问题,像GetFolder
并遍历其文件。但FileExists
会更可读,方便,自然和一致。
的fs.FileExists
不一致的感觉就像一个API设计问题。可能是什么原因?背后有一些想法吗?
另一个解决方法是'如果Dir(“D:\ Folder \ File * .ext”)>“”Then'或者某些DOS命令 – Slai
@Slai'Dir'在VBScript中不存在。 – Tomalak