
04-15-2004, 03:48 PM
|
|
Newcomer
|
|
Join Date: Aug 2003
Location: Maryland, USA
Posts: 15
|
|
Use FileSystemObject
Quote:
|
Originally Posted by lgarcia3
Hi,
I am developing an application where I have to go through the structure of a directory and the files inside its subdirectories to read data in the files. My directory has a variable number of subdirectories and a variable number of files inside every subdirectory. I already have my function that will read the data from the files set up; but I do not know how to get to them dynamically. Any suggestions, code, or ideas are welcome.
Thanks in advance!
|
You can use the FileSystemObject (from Scripting Runtime) and iterate through the different files and subdirectories using a comination of GetFolder, GetFile methods. You can also use Folder.Files() and Folder.SubFolders() methods for navigating through the directory structure. This sample code is from MSDN:
Sub ShowFolderList(folderspec)
Dim fs, f, f1, fc, s
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(folderspec)
Set fc = f.SubFolders
For Each f1 in fc
s = s & f1.name
s = s & vbCrLf
Next
MsgBox s
End Sub
hope this helps,
Linesh
|
__________________
Code warrior
|