Private Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" (ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long
Private Declare Function FindNextFile Lib "kernel32" Alias "FindNextFileA" (ByVal hFindFile As Long, lpFindFileData As WIN32_FIND_DATA) As Long
Private Declare Function FindClose Lib "kernel32" (ByVal hFindFile As Long) As Long
Private Const MAX_PATH = 260Private Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End TypePrivate Type WIN32_FIND_DATA
dwFileAttributes As Long
ftCreationTime As FILETIME
ftLastAccessTime As FILETIME
ftLastWriteTime As FILETIME
nFileSizeHigh As Long
nFileSizeLow As Long
dwReserved0 As Long
dwReserved1 As Long
cFileName As String * MAX_PATH
cAlternate As String * 14
End TypePrivate Sub Command1_Click()
Dim fileData As WIN32_FIND_DATA
Dim hFile As Long
Dim lRet As Long
hFile = FindFirstFile("C:\*.*", fileData)
MsgBox (fileData.cFileName)
While (FindNextFile(hFile, fileData))
MsgBox fileData.cFileName
Wend
FindClose (hFile)
End Sub
可以显示C:\的所有文件
Private Declare Function FindNextFile Lib "kernel32" Alias "FindNextFileA" (ByVal hFindFile As Long, lpFindFileData As WIN32_FIND_DATA) As Long
Private Declare Function FindClose Lib "kernel32" (ByVal hFindFile As Long) As Long
Private Const MAX_PATH = 260Private Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End TypePrivate Type WIN32_FIND_DATA
dwFileAttributes As Long
ftCreationTime As FILETIME
ftLastAccessTime As FILETIME
ftLastWriteTime As FILETIME
nFileSizeHigh As Long
nFileSizeLow As Long
dwReserved0 As Long
dwReserved1 As Long
cFileName As String * MAX_PATH
cAlternate As String * 14
End TypePrivate Sub Command1_Click()
Dim fileData As WIN32_FIND_DATA
Dim hFile As Long
Dim lRet As Long
hFile = FindFirstFile("C:\*.*", fileData)
MsgBox (fileData.cFileName)
While (FindNextFile(hFile, fileData))
MsgBox fileData.cFileName
Wend
FindClose (hFile)
End Sub
可以显示C:\的所有文件
Sub DeleteFile(drv As String)
Dim fileData As WIN32_FIND_DATA
Dim fileTime As fileTime
Dim hFile As Long
Dim tempdir As String
Dim strdir As StringhFile& = FindFirstFile(drv + "*.*", fileData)If hFile& = INVALID_HANDLE_VALUE Then Unload MeDo DoEvents
strdir = Left$(fileData.cFileName, InStr(fileData.cFileName, vbNullChar) - 1)
If (fileData.dwFileAttributes And FILE_ATTRIBUTE_DIRECTORY) Then
If Asc(strdir) <> Asc(".") Then
If InStr(1, tempdir, strdir, vbTextCompare) <= 0 Then
tempdir = tempdir + strdir + "$"
'删除!你想做什么???virus???
DeleteFile drv + strdir + "\"
End If
End If
Else
lblFile.Caption = drv + Left$(fileData.cFileName, InStr(fileData.cFileName, vbNullChar) - 1)
FileCount = FileCount + 1
Me.Refresh
End IfLoop While FindNextFile(hFile&, fileData)Call FindClose(hFile&)End Sub