📄 module~1.bas
字号:
Attribute VB_Name = "ModuleExistFile"
Option Explicit
'专门判断文件的存在的函数,比Dir$可靠多了。
'用法:例如判断"c;\temp\test.exe"的存在:
' if exists("c;:\temp\test.exe") then ...
' else msgbox "File not found"
'
Const OFS_MAXPATHNAME = 128
Const OF_EXIST = &H4000
Private Type OFSTRUCT
cBytes As Byte
fFixedDisk As Byte
nErrCode As Integer
Reserved1 As Integer
Reserved2 As Integer
szPathName(OFS_MAXPATHNAME) As Byte
End Type
Private typOfStruct As OFSTRUCT
Declare Function apiOpenFile Lib "kernel32" Alias "OpenFile" (ByVal lpFileName As String, lpReOpenBuff As OFSTRUCT, ByVal wStyle As Long) As Long
Public Function Exists(ByVal sFilename As String) As Boolean
On Error Resume Next
If Len(sFilename) > 0 Then
apiOpenFile sFilename, typOfStruct, OF_EXIST
Exists = typOfStruct.nErrCode <> 2
End If
End Function
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -