LOOP DIR and retrieve name of image

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

LOOP DIR and retrieve name of image

Post by sal21 »

i need to loop only all dir in C:\Lavori_Vb6\LEGGI_CSV_COMUNI\STEMMI\

i can have this subdir:
1
2
3
...
20

now for each dir i need to list only a image file and retrieve the name of image file


note:
immagine.jpg is the possible list of dir
immagine1.jpg is the possible list of file of dir 1
You do not have the required permissions to view the files attached to this post.

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

Re: LOOP DIR and retrieve name of image

Post by HansV »

I see that C:\Lavori_Vb6\LEGGI_CSV_COMUNI\STEMMI\1 has further subdirectories (AL, AT, ...)
Do you need to list the file names in those subdirectories too?
Best wishes,
Hans

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

Re: LOOP DIR and retrieve name of image

Post by sal21 »

HansV wrote:
22 Aug 2023, 10:53
I see that C:\Lavori_Vb6\LEGGI_CSV_COMUNI\STEMMI\1 has further subdirectories (AL, AT, ...)
Do you need to list the file names in those subdirectories too?
SORRY...
no! only the first subdir
(AL, AT, ...) are a service dir

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

Re: LOOP DIR and retrieve name of image

Post by HansV »

Code: Select all

Sub Test()
    Dim fso As Object
    Dim fld As Object
    Dim sfl As Object
    Dim fil As Object
    Set fso = CreateObject(Class:="Scripting.FileSystemObject")
    Set fld = fso.GetFolder("C:\Lavori_Vb6\LEGGI_CSV_COMUNI\STEMMI")
    For Each sfl In fld.SubFolders
        For Each fil In sfl.Files
            Debug.Print fil.Path ' or fil.Name
        Next fil
    Next sfl
End Sub
Best wishes,
Hans

snb
4StarLounger
Posts: 585
Joined: 14 Nov 2012, 16:06

Re: LOOP DIR and retrieve name of image

Post by snb »

Code: Select all

Sub M_snb()
  msgbox createobject("wscript.shell").exec("cmd /c dir C:\Lavori_Vb6\LEGGI_CSV_COMUNI\STEMMI\*.jpg /b/s").stdout.readall
Emd Sub

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

Re: LOOP DIR and retrieve name of image

Post by sal21 »

HansV wrote:
22 Aug 2023, 11:54

Code: Select all

Sub Test()
    Dim fso As Object
    Dim fld As Object
    Dim sfl As Object
    Dim fil As Object
    Set fso = CreateObject(Class:="Scripting.FileSystemObject")
    Set fld = fso.GetFolder("C:\Lavori_Vb6\LEGGI_CSV_COMUNI\STEMMI")
    For Each sfl In fld.SubFolders
        For Each fil In sfl.Files
            Debug.Print fil.Path ' or fil.Name
        Next fil
    Next sfl
End Sub
GREAT!
tks bro