Results 1 to 4 of 4

Thread: Search for all exe's

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2000
    Location
    Texas
    Posts
    313

    Question

    Is there a way I can search for all .exe's and get there path names, and their icons ect?

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Here's something you could build on, here's Aarons Fastfindfile function which returns an array of files found in a folder + subfolders by a pattern:
    Code:
    Option Explicit
    
    'API Consts, Types and Functions
    Private Const MAX_PATH = 260
    Private Const FILE_ATTRIBUTE_DIRECTORY = &H10
    
    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
    
    Private Declare Function FindClose Lib "kernel32" (ByVal hFindFile As Long) As Long
    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 aFileList As Variant
    Private nFileCount As Long
    
    Function FastFindFiles(ByVal sFolder As String, Optional ByVal sPattern As String = "*") As Variant
        'Initialize the Private File Array and Count, then call the Fast
        'File Recursive Function to populate the Array, then return it.
        nFileCount = 0
        aFileList = Array()
        Screen.MousePointer = vbArrowHourglass
        Call RecurseFindFiles(sFolder, sPattern)
        Screen.MousePointer = vbDefault
        FastFindFiles = aFileList
    End Function
    
    Private Sub RecurseFindFiles(ByVal sFolder As String, ByVal sPattern As String)
    Dim tFD As WIN32_FIND_DATA, lFile As Long, bFound As Long, aSubs() As String, nSubs As Long, sFilename As String
        
        'Make sure the passed folder includes an ending "\"
        If Right(sFolder, 1) <> "\" Then sFolder = sFolder & "\"
        
        'Find the First File in the Specified Location
        lFile = FindFirstFile(sFolder & "*", tFD)
        bFound = lFile
        
        'Loop while a File is found
        While bFound
            'Get the Filename
            sFilename = UCase(Left(tFD.cFileName, InStr(tFD.cFileName, Chr(0)) - 1))
            If (tFD.dwFileAttributes And FILE_ATTRIBUTE_DIRECTORY) Then
                'If it's a Folder, add it to the Sub Folders Array
                If Left(sFilename, 1) <> "." Then
                    ReDim Preserve aSubs(nSubs)
                    aSubs(nSubs) = sFilename
                    nSubs = nSubs + 1
                End If
            Else
                'If it's a File, compare it to the Pattern for a Match
                If sFilename Like UCase(sPattern) Then
                    'If it matches, add it to the File Array
                    ReDim Preserve aFileList(nFileCount)
                    aFileList(nFileCount) = sFolder & sFilename
                    nFileCount = nFileCount + 1
                End If
            End If
            'Find the Next File, (if there is one).
            bFound = FindNextFile(lFile, tFD)
        Wend
        'Close the API Find Handle
        Call FindClose(lFile)
        
        'If there were Sub Folders found, Recurse them too..
        If nSubs Then
            For nSubs = 0 To UBound(aSubs)
                Call RecurseFindFiles(sFolder & aSubs(nSubs), sPattern)
            Next
        End If
    End Sub
    Heres the icon extracting code, put this in the same module:
    Code:
    Declare Function ExtractIcon Lib "shell32.dll" Alias "ExtractIconA" (ByVal hInst As Long, ByVal lpszExeFileName As String, ByVal nIconIndex As Long) As Long
    Declare Function DrawIcon Lib "user32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal hIcon As Long) As Long
    And put this where you want to extract the icons, if you want you could add the icons into a imagelist
    Code:
        Dim item as variant
        For each item in FastFindFiles("C:\","*.exe")
            DrawIcon Picture1.hdc, 0, 0, ExtractIcon(App.hInstance, item, 0)
        Next item
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3
    Guest
    This function does give the list of files(recursively too!) fast enough but it has given out plenty of Dr Watson errors on my client's PCs.


  4. #4
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    'just a wild thought..no icons though

    Code:
    Private Sub Form_Load()
       File1.Path = "C:\"
       File1.Pattern = "*.exe"
    End Sub
    
    
    Private Sub File1_Click()
     
     Dim sFile As String
     sFile = File1.FileName
     
     Dim fso As Object
     Set fso = CreateObject("Scripting.FileSystemObject")
     
     Dim msg As String
     msg = "The file " & sFile & " was created on: " & fso.GetFile(sFile).DateCreated & vbCrLf
     msg = msg & "Last modification to file: " & fso.GetFile(sFile).DateLastModified & vbCrLf
     msg = msg & "Last date file was accessed: " & fso.GetFile(sFile).DateLastAccessed & cbcrlf
     msg = msg & "Something to think about!"
     
     MsgBox msg, vbInformation, "Just A Thought"
    
    End Sub
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

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