PDA

Click to See Complete Forum and Search --> : Searching by document type


Dec 14th, 1999, 10:38 PM
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

Aaron Young
Dec 15th, 1999, 02:23 AM
You would need to Recurse the Local Disk Directories checking the Extension of each file.

You could use the Dir() Function, ie.

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
aarony@redwingsoftware.com
adyoung@win.bright.net