Results 1 to 3 of 3

Thread: Find a file / Search Window

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 1999
    Location
    Prague, Czech Republic
    Posts
    350

    Post

    Hi everybody!

    how could I search trough drivers to find any file? (like the Start->Find->File ...is any way to run this window?)




    ------------------
    Thanks,
    John, 14 years old

  2. #2
    Lively Member
    Join Date
    Jan 2000
    Location
    Thessaloniki ,Greece
    Posts
    100

    Post

    ********************************************
    Create a new project and new module called module1 and put this code
    ********************************************


    Option Explicit

    Public Const sFileSizeBytes = "###,###,###,###,###,###,##0 \b\y\t\e\s"
    Public Const sFmtResult = "###,###,###,##0 \f\o\u\n\d"
    Public Const sFileCount = "###,###,###,##0 f\i\l\e\s\ \f\o\u\n\d"
    Public Const sFolderCount = "###,###,###,##0 f\o\l\d\e\r\s \f\o\u\n\d"

    Public Const MAXDWORD = &HFFFFFFF
    Public Const MAX_PATH = 260
    Public Const INVALID_HANDLE_VALUE = -1
    Public Const FILE_ATTRIBUTE_ARCHIVE = &H20
    Public Const FILE_ATTRIBUTE_COMPRESSED = &H800
    Public Const FILE_ATTRIBUTE_DIRECTORY = &H10
    Public Const FILE_ATTRIBUTE_HIDDEN = &H2
    Public Const FILE_ATTRIBUTE_NORMAL = &H80
    Public Const FILE_ATTRIBUTE_READONLY = &H1
    Public Const FILE_ATTRIBUTE_TEMPORARY = &H100
    Public Const FILE_ATTRIBUTE_FLAGS = FILE_ATTRIBUTE_ARCHIVE Or _
    FILE_ATTRIBUTE_HIDDEN Or _
    FILE_ATTRIBUTE_NORMAL Or _
    FILE_ATTRIBUTE_READONLY

    Public Const DRIVE_UNKNOWNTYPE = 1
    Public Const DRIVE_REMOVABLE = 2
    Public Const DRIVE_FIXED = 3
    Public Const DRIVE_REMOTE = 4
    Public Const DRIVE_CDROM = 5
    Public Const DRIVE_RAMDISK = 6

    Public Type FILETIME
    dwLowDateTime As Long
    dwHighDateTime As Long
    End Type

    Public 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

    'the custom-made UDT for searching
    Public Type FILE_PARAMS
    bRecurse As Boolean 'set True to perform a recursive search
    bList As Boolean 'set True to add results to listbox
    bFound As Boolean 'set only with SearchTreeForFile methods
    sFileRoot As String 'search starting point, ie c:\, c:\winnt\
    sFileNameExt As String 'filenae/filespec to locate, ie *.dll, notepad.exe
    sResult As String 'path to file. Set only with SearchTreeForFile methods
    nFileCount As Long 'total file count matching filespec. Set in FindXXX only
    nFileSize As Double 'total file size matching filespec. Set in FindXXX only
    End Type

    Public Declare Function FindClose Lib "kernel32" _
    (ByVal hFindFile As Long) As Long

    Public Declare Function FindFirstFile Lib "kernel32" _
    Alias "FindFirstFileA" _
    (ByVal lpFileName As String, _
    lpFindFileData As WIN32_FIND_DATA) As Long

    Public Declare Function FindNextFile Lib "kernel32" _
    Alias "FindNextFileA" _
    (ByVal hFindFile As Long, _
    lpFindFileData As WIN32_FIND_DATA) As Long

    Public Declare Function SearchTreeForFile Lib "imagehlp.dll" _
    (ByVal sFileRoot As String, _
    ByVal InputPathName As String, _
    ByVal OutputPathBuffer As String) As Boolean

    Public Declare Function GetLogicalDriveStrings Lib "kernel32" Alias "GetLogicalDriveStringsA" _
    (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long

    Public Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" _
    (ByVal nDrive As String) As Long

    '--end block--'


    ********************************************

    Now in a form put this code and create 3 controls

    1) Commandbutton called command1
    2) ListBox called list1 3) TextBox called text1
    ********************************************

    Option Explicit
    Private Sub Command1_Click()

    Dim FP As FILE_PARAMS

    Call DisplayInit


    '***************************************************
    ' In this variable put the fileroot and the filename
    '***************************************************


    With FP
    .sFileRoot = "C:\windows"
    .sFileNameExt = "command.com"
    .bRecurse = 1
    .bList = 1
    End With

    Call SearchForFiles(FP)
    Call DisplayResults(FP)

    End Sub

    Private Sub DisplayInit()
    'common routine to initialize display

    Text1.Text = "Working ..."
    Text1.Refresh

    List1.Clear
    List1.Visible = False

    End Sub


    Private Sub DisplayResults(FP As FILE_PARAMS)

    'a common routine to display search results

    'this defaults to show the size and count
    'containing in the FP type members, but if
    'FP.sResult is filled (from the Drive and
    'System search methods), that is shown instead.

    Text1.Text = Format$(FP.nFileCount, sFmtResult) & _
    " (" & FP.sFileNameExt & ")"

    If FP.sResult > "" Then
    Text1.Text = "found: " & FP.bFound
    End If
    List1.Visible = True
    End Sub

    Private Function QualifyPath(sPath As String) As String '

    'assures that a passed path ends in a slash

    If Right$(sPath, 1) <> "\" Then
    QualifyPath = sPath & "\"
    Else: QualifyPath = sPath
    End If

    End Function

    Public Function TrimNull(startstr As String) As String

    'returns the string up to the first
    'null, if present, or the passed string
    Dim pos As Integer

    pos = InStr(startstr, Chr$(0))

    If pos Then
    TrimNull = Left$(startstr, pos - 1)
    Exit Function
    End If

    TrimNull = startstr

    End Function

    Private Function GetFileInformation(FP As FILE_PARAMS) As Long

    'local working variables
    Dim WFD As WIN32_FIND_DATA
    Dim hFile As Long
    Dim nSize As Long
    Dim sPath As String
    Dim sRoot As String
    Dim sTmp As String

    'FP.sFileRoot (assigned to sRoot) contains
    'the path to search.
    '
    'FP.sFileNameExt (assigned to sPath) contains
    'the full path and filespec.
    sRoot = QualifyPath(FP.sFileRoot)
    sPath = sRoot & FP.sFileNameExt

    'obtain handle to the first filespec match
    hFile = FindFirstFile(sPath, WFD)

    'if valid ...
    If hFile <> INVALID_HANDLE_VALUE Then

    Do

    'remove trailing nulls
    sTmp = TrimNull(WFD.cFileName)

    'Even though this routine uses filespecs,
    '*.* is still valid and will cause the search
    'to return folders as well as files, so a
    'check against folders is still required.
    If Not (WFD.dwFileAttributes And FILE_ATTRIBUTE_DIRECTORY) _
    = FILE_ATTRIBUTE_DIRECTORY Then

    'file found, so increase the file count
    FP.nFileCount = FP.nFileCount + 1

    'retrieve the size and assign to nSize to
    'be returned at the end of this function call
    nSize = nSize + (WFD.nFileSizeHigh * (MAXDWORD + 1)) + WFD.nFileSizeLow

    'add to the list if the flag indicates
    If FP.bList Then List1.AddItem sRoot & sTmp

    End If

    Loop While FindNextFile(hFile, WFD)


    'close the handle
    hFile = FindClose(hFile)

    End If

    'return the size of files found
    GetFileInformation = nSize

    End Function

    Private Function SearchForFiles(FP As FILE_PARAMS) As Double

    'local working variables
    Dim WFD As WIN32_FIND_DATA
    Dim hFile As Long
    Dim nSize As Long
    Dim sPath As String
    Dim sRoot As String
    Dim sTmp As String

    sRoot = QualifyPath(FP.sFileRoot)
    sPath = sRoot & "*.*"

    'obtain handle to the first match
    hFile = FindFirstFile(sPath, WFD)

    'if valid ...
    If hFile <> INVALID_HANDLE_VALUE Then

    'This is where the met

  3. #3
    Junior Member
    Join Date
    Jan 1999
    Posts
    26

    Post


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width