mtrack81
July 31st, 2001, 12:44 PM
I went to this link that someone in this forum gave me for Access 97..
http://www.mvps.org/access/api/api0006.htm
The problem is that what I really want to do is to prompt the user to enter a file, but the format i want to do it in is similar to the (find file) format that is used in windows start menu. Is there anyway to code this?
Cimperiali
August 1st, 2001, 03:20 AM
'may be this way?
'Example retrieved form Api guide
'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
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)
'KPD-Team 1999
'E-Mail: KPDTeam@Allapi.net
'URL: http://www.allapi.net/
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
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
List1.AddItem path & FileName
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
FindFilesAPI = FindFilesAPI + FindFilesAPI(path & dirNames(i) & "\", SearchStr, FileCount, DirCount)
next i
End If
End Function
Sub Command1_Click()
Dim SearchPath as string, FindStr as string
Dim FileSize as Long
Dim NumFiles as Integer, NumDirs as Integer
Screen.MousePointer = vbHourglass
List1.Clear
SearchPath = Text1.Text
FindStr = Text2.Text
FileSize = FindFilesAPI(SearchPath, FindStr, NumFiles, NumDirs)
Text3.Text = NumFiles & " Files found in " & NumDirs + 1 & " Directories"
Text4.Text = "Size of files found under " & SearchPath & " = " & Format(FileSize, "#,###,###,##0") & " Bytes"
Screen.MousePointer = vbDefault
End Sub
Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood,
Bruno Paris and all the other wonderful people who made and make Codeguru
a great place.
Come back soon, you Gurus.
The Rater