Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Reading through all files on HDD?

Posted on 1999-07-20
Medium Priority
Last Modified: 2010-04-30

Anyone now how can I recursively read through all the directories on my HDD, using VB?

I also need to get on certain files the size, date and if available the extra info like version numbers (i.e on some DLL, EXE file)

Thanks for all help.

Question by:antony061897
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 18

Accepted Solution

deighton earned 200 total points
ID: 1526052
Her's code that scans for the power point program, it reads all files and directories recursively.

Option Explicit
Dim sThePath As String

Private Function bIsHardDrive(ByVal sName As String)

    bIsHardDrive = False
    If InStr(sName, "[") <> 0 And InStr(sName, "]") <> 0 And InStr(sName, "\\") = 0 Then
        If InStr(sName, "[") < InStr(sName, "]") Then
            bIsHardDrive = True
        End If
    End If

End Function

Private Function bIsNetworkDrive(ByVal sName As String)

    bIsNetworkDrive = False
    If InStr(sName, "[") <> 0 And InStr(sName, "]") <> 0 And InStr(sName, "\\") <> 0 Then
        If InStr(sName, "[") < InStr(sName, "]") And _
           InStr(sName, "[") < InStr(sName, "\\") And _
           InStr(sName, "\\") < InStr(sName, "]") Then
            bIsNetworkDrive = True
        End If
    End If

End Function

Private Function scanners(ByVal sFile As String, ByRef bFound As Boolean, ByRef sFoundPath As String) As String

    Dim sPath As String
    Dim lSubDir As Long, lDirCount As Long
    Dim sResult As String, sBasePath As String
    sPath = DirAvail.Path
    lblPath(0).Caption = sPath
    sResult = Dir(sPath & "\" & sFile)
    If sResult <> "" Then
        bFound = True
        sFoundPath = sPath
        Exit Function
    End If
    lDirCount = DirAvail.ListCount - 1
    sBasePath = DirAvail.Path
    For lSubDir = 0 To lDirCount
        DirAvail.Path = DirAvail.List(lSubDir)
        Call scanners(sFile, bFound, sFoundPath)
        DirAvail = sBasePath
        If bFound Then Exit Function
End Function

Private Sub Search(sScanType As String, bFound As Boolean, _
                   bNetworkFound As Boolean, bFixed As Boolean)

        Dim i As Integer

        For i = 0 To drvAvail.ListCount - 1
            On Error Resume Next
            drvAvail.ListIndex = i
            If Err.Number = 0 Then
                If bIsHardDrive(drvAvail.Drive) And sScanType = "F" Or _
                   bIsNetworkDrive(drvAvail.Drive) And sScanType = "N" Or _
                   sScanType = "E" And Not bIsNetworkDrive(drvAvail.Drive) _
                   And LCase(Left(drvAvail.Drive, 1)) <> "a" _
                   And LCase(Left(drvAvail.Drive, 1)) <> "b" And _
                   Dir(Left(drvAvail.Drive, 1) & ":\") = "" And _
                   Dir(Left(drvAvail.Drive, 1) & ":\") = "" Then
                   If sScanType = "F" Then bFixed = True
                    If Err.Number = 0 Then
                        DirAvail.Path = Left(drvAvail.Drive, 1) & ":\"
                        Call scanners("ppview32.exe", bFound, sThePath)
                        If bFound Then Exit For
                    End If
                    If bIsNetworkDrive(drvAvail.Drive) And sScanType = "F" Then
                        bNetworkFound = True
                    End If
                End If
            End If
            On Error GoTo 0
            Err.Number = 0
End Sub

    Private Sub Main()

    Dim bResult As Boolean
    Dim bNetwork As Boolean
    Dim bFixed As Boolean
    Dim iResponse As Integer

    MousePointer = vbHourglass
    Call Search("F", bResult, bNetwork, bFixed)
    MousePointer = vbDefault

    If bFixed = False Then
        MousePointer = vbHourglass
        Call Search("E", bResult, bNetwork, bFixed)
        MousePointer = vbDefault

    End If
    If bResult = False And bNetwork = True Then
        iResponse = MsgBox("The Power Point Viewer could not be found on the fixed drives" & vbCrLf & vbCrLf & "Do you wish to search the network drives", vbYesNo)
        If iResponse = vbYes Then
            MousePointer = vbHourglass
            Call Search("N", bResult, bNetwork, bFixed)
            MousePointer = vbDefault
        End If
    End If
    If bResult Then
    End If

End Sub

Private Function UpdateIni()

    SaveSetting "Autograf", "Presentations", "ViewerPath", sThePath _
    & IIf(Left(sThePath, 1) = "\", "", "\")

End Function


Author Comment

ID: 1526053
Thanks for the quick response, but drvAvail is not defined.

Where do I get this from?

LVL 18

Expert Comment

ID: 1526054
Put a dirlistbox on your form and name it dirAvail
put a drivelistbox on your form and name it drvAvail

also create a control array lblPath(0) and lblPath(1) (or create your own labels and remove the references - or simply remove the references to labels from the code)

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question ( in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question