VB检验文件是否存在

来源:百度知道 编辑:UC知道 时间:2024/04/25 21:54:38
检验c:\***\123.exe
***是text1.text的内容

如果text1.text = 4123
就检查 c:\4123\123.exe
...

if dir("c:\4123\123.exe")<>"" then
end if

很简单。

MsgBox IIf(Len(Dir("c:\" & Text1.Text & "\123.exe")) <> 0, "存在!", "不存在!")

\'用于判断文件是否存在
Function FileExist(FileName As String) As Boolean
On Error Resume Next \'别忘了错误陷阱
Dim FileNum As Integer
FileNum = FreeFile()
Open FileName For Input As #FileNum
If Err = 0 Then
FileExist = True
Else
FileExist = False
End If
Close #FileNum
End Function