依照楼上写测试代码如下:
Dim fe
Set fe = CreateObject("Scripting.FileSystemObject")
If fe.FileExists(compilerPath & "\masm.exe") Then
MsgBox "文件存在!"
Else
MsgBox "文件不存在!"
End If
运行输出:文件不存在!
实有而判断还是无......
用API获的Ini内的字符必须去除多余的"\0"。
Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
Dim s As String * 256
dim compilerPath As String
dim fe
GetPrivateProfileString "IniSection", "Key", "", s, 256, "IniFilePath"
For i = 1 To Len(s)
If Asc(Mid(s, i, 1)) <> 0 Then
compilerPath = compilerPath + Mid(s, i, 1)
Else
Exit For
End If
Next
Set fe = CreateObject("Scripting.FileSystemObject")
If fe.FileExists(compilerPath & "\masm.exe") Then
MsgBox "文件存在!"
Else
MsgBox "文件不存在!"
End If