LOOPING dir and retrieve files name....

User avatar
sal21
PlatinumLounger
Posts: 4362
Joined: 26 Apr 2010, 17:36

LOOPING dir and retrieve files name....

Post by sal21 »

C:\Lavori_Vb6\LEGGI_CSV_COMUNI\STEMMI\

in this dir have other sub dir, similar
\1
\2
\3
...
xx

in internal of each subdir have a files, i need a list of files with this format:

1-files.txt
1-prova.gif
ecc...
You do not have the required permissions to view the files attached to this post.

User avatar
HansV
Administrator
Posts: 78530
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: LOOPING dir and retrieve files name....

Post by HansV »

Code: Select all

Sub LoopSubDir()
    Const strPath = "C:\Lavori_Vb6\LEGGI_CSV_COMUNI\STEMMI\"
    Dim fso As Object
    Dim fld As Object
    Dim sfl As Object
    Dim fil As Object
    Dim strOutput As String
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set fld = fso.GetFolder(strPath)
    For Each sfl In fld.SubFolders
        For Each fil In sfl.Files
            strOutput = sfl.Name & "-" & fil.Name
            Debug.Print strOutput
        Next fil
    Next sfl
End Sub
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4362
Joined: 26 Apr 2010, 17:36

Re: LOOPING dir and retrieve files name....

Post by sal21 »

HansV wrote:
02 Aug 2023, 14:55

Code: Select all

Sub LoopSubDir()
    Const strPath = "C:\Lavori_Vb6\LEGGI_CSV_COMUNI\STEMMI\"
    Dim fso As Object
    Dim fld As Object
    Dim sfl As Object
    Dim fil As Object
    Dim strOutput As String
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set fld = fso.GetFolder(strPath)
    For Each sfl In fld.SubFolders
        For Each fil In sfl.Files
            strOutput = sfl.Name & "-" & fil.Name
            Debug.Print strOutput
        Next fil
    Next sfl
End Sub
Great bro!