Results 1 to 2 of 2

Thread: Searching by document type

  1. #1
    Guest

    Post

    Any ideas on creating an application that will search and extract files according to type, ie *.txt, *.dll. They need to have have a record of there location and size

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    You would need to Recurse the Local Disk Directories checking the Extension of each file.

    You could use the Dir() Function, ie.
    Code:
    Private sLog As String
    
    Private Sub LogFilesOfType(ByVal sType As String, Optional ByVal sInitDir As String = "C:\")
        Dim sSubFolder() As String
        Dim iSubFolder As Long
        Dim sDir As String
        Dim bLogged As Boolean
        
        On Error Resume Next
        If Right$(sType, 1) <> "," Then sType = sType & ","
        If Right$(sInitDir, 1) <> "\" Then sInitDir = sInitDir & "\"
        sDir = Dir(sInitDir & "*", vbArchive + vbHidden + vbNormal + vbReadOnly + vbSystem + vbDirectory)
        While Len(sDir)
            If (GetAttr(sInitDir & sDir) And vbDirectory) = vbDirectory Then
                If Left(sDir, 1) <> "." Then
                    ReDim Preserve sSubFolder(iSubFolder)
                    sSubFolder(iSubFolder) = sDir
                    iSubFolder = iSubFolder + 1
                End If
            ElseIf InStr(sDir, ".") Then
                If InStr(sType, Mid$(sDir, InStr(sDir, ".")) & ",") Then
                    If Not bLogged Then
                        sLog = sLog & vbCrLf & sInitDir & vbCrLf
                        bLogged = True
                    End If
                    sLog = sLog & "  " & Left$(sDir & Space(50), 50) & Chr(9) & Format(FileDateTime(sInitDir & sDir), "HH:MM:SS AM/PM MM/DD/YYYY") & Chr(9) & FileLen(sInitDir & sDir) & vbCrLf
                    Caption = "Logged: " & Val(Mid$(Caption, 9)) + 1
                End If
            End If
            sDir = Dir
        Wend
        If iSubFolder Then
            For iSubFolder = 0 To UBound(sSubFolder)
                Call LogFilesOfType(sType, sInitDir & sSubFolder(iSubFolder))
            Next
        End If
    End Sub
    
    Private Sub Command1_Click()
        sLog = ""
        Call LogFilesOfType(".txt,.scr")
        Open "C:\Log.txt" For Output As 1
            Print #1, sLog
        Close 1
        Shell "notepad.exe C:\log.txt", vbNormalFocus
    End Sub
    To use simplay pass LogFilesOfType() a Comma-Delimited String on Extensions to Search For and an Optional Starting Folder/Drive.

    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]

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