Link to home
Start Free TrialLog in
Avatar of jack niekerk
jack niekerkFlag for Netherlands

asked on

Finding names of files in a directory with sub-directories in VB6

Need a way to debug.print in a loop in VB6   names of files in in directory AND the all names in de sub-directory below that path and if more sub-sub directories below that path also
User generated image
Avatar of John Tsioumpris
John Tsioumpris
Flag of Greece image

Check this post for sample code : http://www.freevbcode.com/ShowCode.asp?ID=8299
Avatar of jack niekerk

ASKER

hi John,  thanks  for the firebird tabel test i have to wait to the weekend , then 2 days to be safe
Take your time Jack....test it thoroughly to be 100% certain.
Avatar of Bill Prew
Bill Prew

Here's a simple example that shows the basics of the recursive drill down into subfolders, listing files and folders along the way.  You will need a reference to the "Microsoft Scripting Runtime".

    Dim fso As Scripting.FileSystemObject

    Sub Main()
        EE29177468()
    End Sub

    Private Sub EE29177468()
        Dim fld As Scripting.Folder

        fso = New Scripting.FileSystemObject
        fld = fso.GetFolder("C:\Temp\")

        ListFiles(fld)
    End Sub

    Private Sub ListFiles(fld As Scripting.Folder)
        Dim fold As Scripting.Folder
        Dim fil As Scripting.File

        Console.WriteLine(fld.Path)

        For Each fil In fld.Files
            Console.WriteLine("  " & fil.Path)
        Next

        For Each fold In fld.SubFolders
            ListFiles(fold)
        Next
    End Sub

Open in new window


»bp
hello Bill
I modified like this , if just debug.print works i'am happy , at that point i do my work on the namens off file

got only this error on  " invalid use of property ""   at: line    fld = fso.GetFolder("I:\") <<<<<

Please advise, thanks


Private Sub cmdtest2_Click()
'=========================
        Dim fld  As Scripting.Folder
        fso = New Scripting.FileSystemObject
        fld = fso.GetFolder("I:\")
        ListFiles (fld)
    End Sub

    Private Sub ListFiles(fld As Scripting.Folder)
    '============================
        Dim fold As Scripting.Folder
        Dim fil As Scripting.file

        Debug.Print fld.Path

        For Each fil In fld.Files
            Debug.Print fil.Path
        Next

        For Each fold In fld.SubFolders
         Debug.Print ListFiles(fold)
        Next
    End Sub
ASKER CERTIFIED SOLUTION
Avatar of John Tsioumpris
John Tsioumpris
Flag of Greece image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Are you working in Visual Studio and VB there, or are you doing a VBA project in Office, or something else?


»bp
only VB6-pro
hi John that solved the problem Thanks !