Do loop until no more folder is found

P

Piotr (Peter)

Hi,

I'm writing on behalf of my colleague who needs to write a loop that opens
folders within a folder X until no furhter folder is found in that folder X.

Any help highly appreciated.
 
J

Jack Leach

You can do this using the Dir() function an applying the vbDirectory
constant. I don't have time to fully test a loop to do this at the moment,
but that would be the route to go. You may find this link useful...

http://www.allenbrowne.com/ser-59.html

--
Jack Leach
www.tristatemachine.com

"I haven''t failed, I''ve found ten thousand ways that don''t work."
-Thomas Edison (1847-1931)
 
P

Piotr (Peter)

Thanks Alex for this. It has been slightly amended so that the code ignores
folders "." and "..", which are normally taken into account due to the way
the code "sees" folders and I presume is back to DOS era (code below).

Dim strFolder As String

strFolder = Dir(fnWskazFolder, vbDirectory)
Do While Len(strFolder) > 0
If strFolder = "." Then
strFolder = Dir
End If
If strFolder = ".." Then
strFolder = Dir
End If

Debug.Print strFolder
strFolder = Dir
Loop


Thanks everybody for your contribution.

Regards,
Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top