Find Code:
All Words
Any of the Words
Exact Phrase
Home
:
Code
:
Forums
:
Submit
:
Mailing List
:
About
:
Contact
Code
All
VB.NET
ASP.NET
C#
VB Classic
ASP Classic
Snippets
Popular
Resources
Submit Code
Forums
Articles
Tips
Links
Books
Contest
Link to us
Simple Recursive folder name scan
Author:
Gareth
Submitted:
2/27/2009
Version:
VB6
Compatibility:
VB6
Category:
File Manipulation
Views:
13183
This is a really simple example of a recursive scan of folders and all sub folders that anybody should be able to understand. My eyes glazed over looking at most code examples of this so I wrote this to show how it can be really simply shown.
Declarations:
'none
Code:
Dim path, fpath, mbs Private Sub Form_Load() 'recursively scan all folders and sub folders path = "C:\program files" 'put a valid path to a folder between "". fpath = path 'Choose a folder with a few sub folders and follow what is going Call ShowFolderList(path) 'in single step mode. MsgBox mbs End Sub Sub ShowFolderList(folderspec) 'For this to work go to Menu:- Project-References Dim fs, f, f1, fc, s 'and make sure "Microsoft Scripting Runtime" is ticked. Set fs = CreateObject("Scripting.FileSystemObject") Set f = fs.GetFolder(folderspec) Set fc = f.SubFolders fpath1 = fpath 'this looks unnecessary... For Each f1 In fc mbs = mbs & f1.Name 'for the message box at the end mbs = mbs & vbCrLf 'build the string with carriage returns, linefeeds. fpath = fpath1 fpath = fpath & "\" & f1.Name 'modify new path 'Debug.Print fpath 'press ctrl G to open the immediate window and see output. Call ShowFolderList(fpath) 'the recursion bit Next fpath = fpath1 'set a breakpoint here to see how the paths change End Sub 'each time the routine drops out
Home
|
Forums
|
Submit
|
Books
|
Mailing List
|
Advertising
|
About
|
Contact
© 2024 A1VBCode. All rights reserved.
Legal disclaimer & terms of use
Privacy statement