Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > Directory and subdirectories problem


Reply
 
Thread Tools Display Modes
  #1  
Old 04-15-2004, 02:58 PM
lgarcia3 lgarcia3 is offline
Regular
 
Join Date: Jan 2001
Location: Houston, TX
Posts: 68
Default Directory and subdirectories problem


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!
Reply With Quote
  #2  
Old 04-15-2004, 03:48 PM
linesh linesh is offline
Newcomer
 
Join Date: Aug 2003
Location: Maryland, USA
Posts: 15
Talking 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
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
list files in directory and subdirectories tymahshoo Excel 21 09-27-2004 10:00 AM
searching a directory Proto File I/O and Registry 1 09-12-2003 09:19 PM
Using Recursion to Search a Directory BillSoo Tutors' Corner 2 08-20-2002 05:03 PM
Directories & subdirectories MarkG General 6 12-04-2001 03:30 PM

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->