'*********************************************************
'* 名称:FileExists%(filename$)
'* 功能:此函数用于判断文件是否存在
'* 用法:FileExists%('文件名称')
'* 文件不存在返回 0
'*********************************************************
Function FileExists%(filename$)
Dim F%
On Error Resume Next
F% = FreeFile
Open filename$ For Input As #F%
Close #F%
FileExists% = Not (Err <> 0)
End Function
'* 名称:FileExists%(filename$)
'* 功能:此函数用于判断文件是否存在
'* 用法:FileExists%('文件名称')
'* 文件不存在返回 0
'*********************************************************
Function FileExists%(filename$)
Dim F%
On Error Resume Next
F% = FreeFile
Open filename$ For Input As #F%
Close #F%
FileExists% = Not (Err <> 0)
End Function
Const vbBackslash = "\"
Const vbAllFiles = "*.*"
Const vbKeyDot = 46Private Sub SearchDirs(curpath$)
Dim dirs%, dirbuf$(), i%
DoEvents
hItem$ = Dir(curpath$, vbDirectory) Do While hItem$ <> ""
If (GetAttr(curpath$ & hItem$) And vbDirectory) = vbDirectory
Then
If hItem$ <> "." And hItem <> ".." Then
If (dirs% Mod 10) = 0 Then ReDim Preserve dirbuf$(dirs% +
10)
dirs% = dirs% + 1
dirbuf$(dirs%) = curpath$ & hItem$
End If
End If
hItem$ = Dir
Loop Call SearchFileSpec(curpath$) For i% = 1 To dirs%: SearchDirs dirbuf$(i%) & vbBackslash: Next i%End Sub
Private Sub SearchFileSpec(curpath$)
hFile$ = Dir(curpath$ & Filespec$)
While Trim$(hFile$) <> ""
Text1 = Text1 & curpath$ & hFile$ & vbCrLf
hFile$ = Dir
Wend
End SubPrivate Sub Form_Load()
Text1 = ""
curpath$ = "C:\"
SearchDirs (curpath$)
End Sub
FindFirstFile VB声明
Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" (ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long
说明
根据文件名查找文件
返回值
Long,如执行成功,返回一个搜索句柄。如果出错,返回一个INVALID_HANDLE_VALUE常数,一旦不再需要,应该用FindClose函数关闭这个句柄
参数表
参数 类型及说明
lpFileName String,欲搜索的文件名。可包含通配符,并可包含一个路径或相对路径名
lpFindFileData WIN32_FIND_DATA,这个结构用于装载与找到的文件有关的信息。该结构可用于后续的搜索
注解
由这个函数返回的句柄可以作为一个参数用于FindNextFile函数。这样一来,就可以方便的枚举出与lpFileName参数指定的文件名相符的所有文件
Top