Refresh Directory File List

T

Todd Lemen

I have routine that uses the FileSystemObject to
determine the existance of a folder. If the folder is
found, I pass control to a function that uses a Scripting
Directory object to populate a list with the names of
subdirectories. If the folder is not found, it offers
the user a chance to create one. While it does so, it
creates several subfolders. When this routine finishes,
the procedure deconstructs the FileSystemObject (by
setting the FSO variable to Nothing) and passes control
to the aforementioned "populate the list" function.

Problem seems to be a file system refresh... When
control passes after creating the folder and subfolders,
I have to exit these routines entirely before the
Directory object can read the new folder's subfolders. Is
there a "refresh file system" command somewhere?
 
D

Douglas J. Steele

Why not scrap FSO, and use strictly VBA commands?

You can check for the existence of a folder using the Dir function:

strFolder = "C:\Temp"
If Len(Dir(strTemp, vbDirectory)) > 0 Then
' Folder exists
Else
' Folder doesn't exist
End If

You can create folders using the MkDir statement:

MkDir "C:\Temp"
MkDir "C:\Temp\SubDir"
 
D

Douglas J. Steele

That's odd: I've never encountered any such problems.

Are you creating the folders on a network share or on the workstation? What
does your code look like?
 
T

Todd Lemen

OK... I stepped through the code, and found my error. I
was passing the wrong directory name to my GetSubFolder
function. All is working.

Thanks again for your help, Doug!

TL
 

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