PC Review


Reply
Thread Tools Rate Thread

Do loop until no more folder is found

 
 
Piotr (Peter)
Guest
Posts: n/a
 
      9th Feb 2010
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.


 
Reply With Quote
 
 
 
 
Allen Browne
Guest
Posts: n/a
 
      9th Feb 2010
To list the files (including folders) see help with Dir. After setting it
up, you just use Dir repeatedly until it returns a zero-length string.

To test if it's a folder, test:
If (GetAttr(strFile) And vbdirectory) = vbDirectory

Example of testing for a folder:
http://allenbrowne.com/func-11.html

Example of listing files recursively:
http://allenbrowne.com/ser-59.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.


"Piotr (Peter)" <(E-Mail Removed)> wrote in message
news:20F41FAB-DB0C-4368-B0B1-(E-Mail Removed)...
> 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.
>
>

 
Reply With Quote
 
Jack Leach
Guest
Posts: n/a
 
      9th Feb 2010
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)



"Piotr (Peter)" wrote:

> 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.
>
>

 
Reply With Quote
 
Alex Dybenko
Guest
Posts: n/a
 
      9th Feb 2010
Hi,
something like this:

strFolder = dir("c:\", vbdirectory)
do while len(strFolder)>0
debug.print strFolder
strFolder=dir
loop

--
Best regards,
___________
Alex Dybenko (MVP)
http://accessblog.net
http://www.PointLtd.com


"Piotr (Peter)" <(E-Mail Removed)> wrote in message
news:20F41FAB-DB0C-4368-B0B1-(E-Mail Removed)...
> 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.
>
>

 
Reply With Quote
 
Piotr (Peter)
Guest
Posts: n/a
 
      10th Feb 2010
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

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Loop through found value GregR Microsoft Excel Programming 4 2nd Mar 2007 06:55 PM
Chkdsk created a Found Folder and placed files in it that it found. Alfons Windows XP Help 7 17th Oct 2006 04:36 PM
Stop the loop when found. =?Utf-8?B?aGZhemFs?= Microsoft Excel Programming 1 16th Feb 2006 11:57 PM
Windows Backup " The saved selection file ... not found " or "skipped files in folder ... folder not found" error SOLVED! Matthew Mucklo Windows XP General 1 11th May 2004 03:34 AM
Windows Backup " The saved selection file ... not found " or "skipped files in folder ... folder not found" error SOLVED! Matthew Mucklo Microsoft Windows 2000 1 11th May 2004 03:34 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:39 AM.