By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,089 Members | 1,388 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,089 IT Pros & Developers. It's quick & easy.

Drilling down for zip files, how can I reach every subdirectory?

Lokean
P: 71
Hi folks,

Here's what I have so far...
Expand|Select|Wrap|Line Numbers
  1. Dim fso, fol, subfol, fo, fls, fl, subfol2, subfol3
  2.  
  3. sSearchString = "C:\"
  4.  
  5.     Set fso = CreateObject("Scripting.FileSystemObject")
  6.     Set fol = fso.getfolder("C:\")
  7.     Set subfol = fol.subfolders
  8.  
  9.  
  10.     For Each fo In subfol
  11.         On Error GoTo Resumeit
  12.        Set fls = fo.Files
  13.  
  14.        'Else
  15.        For Each fl In fls
  16.           If UCase(Right((fl.Name), 3)) = "ZIP" Then
  17.             ' MsgBox fl.Name
  18.           End If
  19.         Next fl
  20.  
  21. Resumeit2:
  22.     Next fo
This gets me down to one level below C:\, but I need to get to every subdirectory and pull out all the zip files that are floating around.

application.filesearch does not recognize .zip files as files, so that trick is out.

This is as close as I've come.

Can anyone help me drill down from here? Is there a better method?

Thanks in advance.
Apr 3 '07 #1
Share this Question
Share on Google+
1 Reply


Expert 5K+
P: 8,434
I have tackled this exact problem of traversing folders in the past. The technique I came up with (based largely on someone else's example, I think) is a reentrant routine - that is, one which calls itself. I'll have a dig around for some source code later. but the general method was something like this (just pseudo-code)...

Expand|Select|Wrap|Line Numbers
  1. Sub ProcessFolder (fld as Folder)
  2.  
  3.   For each SubFolder in fld
  4.     ProcessFolder SubFolder
  5.   Next
  6.  
  7.   For each File in fld
  8.     ProcessFile File
  9.   Next
  10.  
  11. End Sub
  12.  
  13. Sub ProcessFile (fil as File)
  14.  
  15.   ' Do whatever you want with fil here.
  16.  
  17. End Sub
Note, when writing a routine which will call itself like this, where each iteration must be separate, it's important to avoid using Static variables (unless you really know you need them)
Apr 3 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.