?? menumfile.bas
字號:
Attribute VB_Name = "MEnumFile"
'Create a form with a command button (command1), a list box (list1)
'and four text boxes (text1, text2, text3 and text4).
'Type in the first textbox a startingpath like c:\
'and in the second textbox you put a pattern like *.* or *.txt
Option Explicit
Public strSelFileFullName() As String
Public blnExportCancelled As Boolean
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 GetFileAttributes Lib "kernel32" Alias "GetFileAttributesA" (ByVal lpFileName As String) As Long
Private Declare Function FindClose Lib "kernel32" (ByVal hFindFile As Long) As Long
Const MAX_PATH = 260
Const MAXDWORD = &HFFFF
Const INVALID_HANDLE_VALUE = -1
Const FILE_ATTRIBUTE_ARCHIVE = &H20
Const FILE_ATTRIBUTE_DIRECTORY = &H10
Const FILE_ATTRIBUTE_HIDDEN = &H2
Const FILE_ATTRIBUTE_NORMAL = &H80
Const FILE_ATTRIBUTE_READONLY = &H1
Const FILE_ATTRIBUTE_SYSTEM = &H4
Const FILE_ATTRIBUTE_TEMPORARY = &H100
Private Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Private 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 Type
Function StripNulls(OriginalStr As String) As String
If (InStr(OriginalStr, Chr(0)) > 0) Then
OriginalStr = left(OriginalStr, InStr(OriginalStr, Chr(0)) - 1)
End If
StripNulls = OriginalStr
End Function
Function FindFilesAPI(Path As String, SearchStr As String, FileCount As Integer, DirCount As Integer, BlnAllDir As Boolean, lblSearching As Label)
'KPD-Team 1999
'E-Mail: KPDTeam@Allapi.net
'URL: http://www.allapi.net/
On Error GoTo ErrHandle
Dim Filename As String ' Walking filename variable...
Dim DirName As String ' SubDirectory Name
Dim dirNames() As String ' Buffer for directory name entries
Dim nDir As Integer ' Number of directories in this path
Dim i As Integer ' For-loop counter...
Dim hSearch As Long ' Search Handle
Dim WFD As WIN32_FIND_DATA
Dim Cont As Integer
Dim strPath As String
If Right(Path, 1) <> "\" Then Path = Path & "\"
strPath = Path
' Search for subdirectories.
nDir = 0
ReDim dirNames(nDir)
Cont = True
hSearch = FindFirstFile(Path & "*", WFD)
If hSearch <> INVALID_HANDLE_VALUE Then
Do While Cont
DirName = StripNulls(WFD.cFileName)
' Ignore the current and encompassing directories.
If (DirName <> ".") And (DirName <> "..") Then
' Check for directory with bitwise comparison.
If GetFileAttributes(Path & DirName) And FILE_ATTRIBUTE_DIRECTORY Then
dirNames(nDir) = DirName
lblSearching.Caption = "正在查找文件夾:" & DirName & "..."
lblSearching.Refresh
DirCount = DirCount + 1
nDir = nDir + 1
ReDim Preserve dirNames(nDir)
End If
End If
Cont = FindNextFile(hSearch, WFD) 'Get next subdirectory.
Loop
Cont = FindClose(hSearch)
End If
' Walk through this directory and sum file sizes.
hSearch = FindFirstFile(Path & SearchStr, WFD)
Cont = True
If hSearch <> INVALID_HANDLE_VALUE Then
While Cont
Filename = StripNulls(WFD.cFileName)
If (Filename <> ".") And (Filename <> "..") Then
FindFilesAPI = FindFilesAPI + (WFD.nFileSizeHigh * MAXDWORD) + WFD.nFileSizeLow
FileCount = FileCount + 1
lblSearching.Caption = "正在查找文件:" & Filename & "..."
lblSearching.Refresh
AddNewFile Path & Filename
End If
Cont = FindNextFile(hSearch, WFD) ' Get next file
Wend
Cont = FindClose(hSearch)
End If
If BlnAllDir Then
' If there are sub-directories...
If nDir > 0 Then
' Recursively walk into them...
For i = 0 To nDir - 1
FindFilesAPI = FindFilesAPI + FindFilesAPI(Path & dirNames(i) & "\", SearchStr, FileCount, DirCount, BlnAllDir, lblSearching)
Next i
End If
End If
Exit Function
ErrHandle:
ShowMessageBoxEx Err.Description
End Function
Function FindFileAPI(Path As String, SearchStr As String) As String
'KPD-Team 1999
'E-Mail: KPDTeam@Allapi.net
'URL: http://www.allapi.net/
On Error GoTo ErrHandle
Dim Filename As String ' Walking filename variable...
Dim DirName As String ' SubDirectory Name
Dim dirNames() As String ' Buffer for directory name entries
Dim nDir As Integer ' Number of directories in this path
Dim i As Integer ' For-loop counter...
Dim hSearch As Long ' Search Handle
Dim WFD As WIN32_FIND_DATA
Dim Cont As Integer
If Right(Path, 1) <> "\" Then Path = Path & "\"
' Search for subdirectories.
nDir = 0
ReDim dirNames(nDir)
Cont = True
hSearch = FindFirstFile(Path & "*", WFD)
If hSearch <> INVALID_HANDLE_VALUE Then
Do While Cont
DirName = StripNulls(WFD.cFileName)
' Ignore the current and encompassing directories.
If (DirName <> ".") And (DirName <> "..") Then
' Check for directory with bitwise comparison.
If GetFileAttributes(Path & DirName) And FILE_ATTRIBUTE_DIRECTORY Then
dirNames(nDir) = DirName
nDir = nDir + 1
ReDim Preserve dirNames(nDir)
End If
End If
Cont = FindNextFile(hSearch, WFD) 'Get next subdirectory.
Loop
Cont = FindClose(hSearch)
End If
' Walk through this directory and sum file sizes.
hSearch = FindFirstFile(Path & SearchStr, WFD)
Cont = True
Dim str As String
If hSearch <> INVALID_HANDLE_VALUE Then
While Cont
Filename = StripNulls(WFD.cFileName)
If (Filename <> ".") And (Filename <> "..") Then
' FindFilesAPI = FindFilesAPI + (WFD.nFileSizeHigh * MAXDWORD) + WFD.nFileSizeLow
' FileCount = FileCount + 1
FindFileAPI = Path & Filename
Exit Function
End If
Cont = FindNextFile(hSearch, WFD) ' Get next file
Wend
Cont = FindClose(hSearch)
End If
' If there are sub-directories...
If nDir > 0 Then
' Recursively walk into them...
For i = 0 To nDir - 1
FindFileAPI = FindFileAPI + FindFileAPI(Path & dirNames(i) & "\", SearchStr)
Next i
End If
Exit Function
ErrHandle:
ShowMessageBoxEx Err.Description
End Function
Public Sub FillEnumGrid(strPath As String, BlnAllDir As Boolean, strMsgType As String, lblSearching As Label)
Dim SearchPath As String, FindStr As String
Dim FileSize As Long
Dim NumFiles As Integer, NumDirs As Integer
Screen.MousePointer = vbHourglass
If Not UCase(strMsgType) = UCase("all") Then
If UCase(strMsgType) = UCase("eml") Then
SearchPath = strPath
FindStr = "*.eml"
FileSize = FindFilesAPI(SearchPath, FindStr, NumFiles, NumDirs, BlnAllDir, lblSearching)
End If
If UCase(strMsgType) = UCase("msg") Then
SearchPath = strPath
FindStr = "*.msg"
FileSize = FindFilesAPI(SearchPath, FindStr, NumFiles, NumDirs, BlnAllDir, lblSearching)
End If
Else
SearchPath = strPath
FindStr = "*.eml"
FileSize = FindFilesAPI(SearchPath, FindStr, NumFiles, NumDirs, BlnAllDir, lblSearching)
SearchPath = strPath
FindStr = "*.msg"
FileSize = FindFilesAPI(SearchPath, FindStr, NumFiles, NumDirs, BlnAllDir, lblSearching)
End If
Screen.MousePointer = vbDefault
End Sub
'********************************************************************************
'新增合同文件
Private Sub AddNewFile(strFileName As String)
Dim lRow As Long
Dim strFullName As String
Dim strFilePath As String
Dim ObjFileSystem As New FileSystemObject
With frmLibSearch.GridFile
strFullName = strFileName
If ObjFileSystem.FileExists(strFullName) Then
.AddRow
Else
Exit Sub
End If
lRow = .Rows
strFilePath = ObjFileSystem.GetParentFolderName(strFullName)
strFileName = ObjFileSystem.GetFileName(strFullName)
.CellText(lRow, GridContractFileCol.strFileNO) = lRow
.CellText(lRow, GridContractFileCol.strFileName) = strFileName
.CellIcon(lRow, GridContractFileCol.strFileName) = IIf(InStr(1, UCase(strFileName), UCase(".eml")) > 0, frmLibSearch.m_cSysIls.ImageItemIndex("*.eml"), frmLibSearch.m_cSysIls.ImageItemIndex("*.msg"))
.CellText(lRow, GridContractFileCol.strMemo) = IIf(InStr(1, UCase(strFileName), UCase(".eml")) > 0, "EML", "MSG")
.CellText(lRow, GridContractFileCol.strPath) = strFilePath
.CellText(lRow, GridContractFileCol.strFileFullName) = strFullName
End With
End Sub
'********************************************************************************
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -