DIR Method

R

Red

All help is appreciated as I'm now rapidly going mad!

I'm trying to read all mpp files in directory f:\ which has several sub
directories. The first loop I've written runs through the first level of
directories and works fine on its own. The second loop uses the first to run
through all the subdirectories and also works fine on it's own. But put the
2 together and I get Error 5, Invalid Procedure, Call or Argument on line
Portfolio = Dir. I don't understand!!

' Display the names in Project_plans that represent directories.
RootPath = "f:\PD Portfolios\" ' Set the path.
Portfolio = Dir(RootPath, vbDirectory) ' Retrieve the first entry.
Do While Portfolio <> "" ' Start the loop.
' Ignore the current directory and the encompassing directory.
If Portfolio <> "." And Portfolio <> ".." Then
' Use bitwise comparison to make sure Portfolio is a directory.
If (GetAttr(RootPath & Portfolio) And vbDirectory) = vbDirectory
Then
JobPath = RootPath & Portfolio & "\"
JobType = Dir(JobPath, vbDirectory)
Do While JobType <> "" ' Start the loop
If JobType <> "." And JobType <> ".." Then
' Use bitwise comparison to make sure Portfolio is a
directory.
If (GetAttr(JobPath & JobType) And vbDirectory) =
vbDirectory Then
Debug.Print Portfolio ' Display entry only if it
End If ' It represnet s a directory
End If
JobType = Dir
Loop
End If ' it represents a directory
End If
Portfolio = Dir ' Get next entry.
Loop
 
R

Red

I've finally worked it out!!

For loop 1 the values should be stored in an array and the loop closed.
These values are then used in loop 2. Easy when you know how!
 

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