473,396 Members | 1,966 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Search a folder with VB for sub-folder names

I'm looking for code that I can use to return the names of sub folders
which exist in a folder. The end goal is to be able to then use the
DIR(*) function to return the name of all files in each folder.

I've been searching the forums and while I've found a fair amount of
info, nothing seems quite what I'm chasing.

Thanks again

Reg

Jul 12 '06 #1
2 8741
Regnab wrote:
I'm looking for code that I can use to return the names of sub folders
which exist in a folder. The end goal is to be able to then use the
DIR(*) function to return the name of all files in each folder.
This is very old code. It does not reflect my current coding practices.
This morning I tested it as the temp sub shows. It seems to work OK.
News clients may insert line breaks which must be removed before the
code can be used. Using it with a base drive such as GetFolders("c:\")
which has many folders and sub folders may take a very long time. Other
newer simpler methods may exist and it's quite likely they will be
posted.

Function GetFolders(ByVal vStrRootFolder As String) As Variant
Dim aFolders() As Variant, strFolder As String, _
intFolder As Integer, intStart As Integer
If Right(vStrRootFolder, 1) <"\" Then vStrRootFolder =
vStrRootFolder & "\"
ReDim aFolders(intStart)
aFolders(intStart) = vStrRootFolder
Do
strFolder = Dir(aFolders(intStart), vbDirectory)
Do While strFolder <""
If strFolder <"." And strFolder <".." Then
strFolder = aFolders(intStart) & strFolder
If (GetAttr(strFolder) And vbDirectory) = vbDirectory
Then
intFolder = UBound(aFolders) + 1
If Right(strFolder, 1) <"\" Then strFolder =
strFolder & "\"
ReDim Preserve aFolders(LBound(aFolders) To
intFolder)
SysCmd acSysCmdSetStatus, "Locating Folders " &
strFolder
aFolders(intFolder) = strFolder
End If
End If
strFolder = Dir()
Loop
intStart = intStart + 1
Loop Until intStart UBound(aFolders)
GetPathExit:
GetFolders = aFolders
Erase aFolders
End Function

Sub temp()
Dim aFolders As Variant
Dim z As Long
aFolders = GetFolders("C:\Documents and Settings\Lyle Fairfield\My
Documents\Excel\")
For z = LBound(aFolders) To UBound(aFolders)
Debug.Print aFolders(z)
Next z
End Sub

Jul 12 '06 #2
Thanks Lyle - very smick. If that's your old coding, you must be doing
alright these days. While I must admit I don't understand a lot of it,
it does achieve what I'm chasing for which I am most appreciative...

Jul 12 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: amoona | last post by:
Hi… I’m doing a search page form my work for their library. Since this is the first time I work with ASP I’m facing some problems. Each library item has different search data, I was able to...
2
by: Scott | last post by:
I'm trying to use the HTMLHelp API calls in a VB.NET program because I want a little more functionality than is offered by the Help class in .NET. Everything works fine except for displaying the...
4
by: Dica | last post by:
i apologize for what is no doubt a very rudimentary question, but i'm still trying to wrap my brain around .net coding habits. in classic asp, if i wanted to show search results, i'd just post the...
1
by: Eric | last post by:
Hi: I have two files. I search pattern ":" from emails text file and save email contents into a database. Another search pattern " field is blank. Please try again.", vbExclamation + vbOKOnly...
4
by: BenCoo | last post by:
Hello, In a Binary Search Tree I get the error : Object must be of type String if I run the form only with the "Dim bstLidnummer As New BinarySearchTree" it works fine. Thanks for any...
12
by: ljungers | last post by:
I'm on the home streach of my project and found that my "Reset for New Search" command button not working as desired. What should happen is that when the button is clicked a Event Procedure is run....
0
by: sandy21380 | last post by:
I have the following code in my program allowing users to search for entries matching up to five different criteria at once. I changed the form to now contain a subform and would like to allow the...
1
by: captainmorgan | last post by:
I have included an unbound field called which is used to quickly move to the desired record, by searching the last name field. I have been using this code for a few years, with only one...
5
by: Deano | last post by:
Perhaps this has been asked before but there might be some up to date thinking about this. I really need a better search function for my asset register. I allow assets to be entered and tracked...
0
by: JamesOo | last post by:
I have the code below, but I need to make it searchable in query table, below code only allowed seach the table which in show mdb only. (i.e. have 3 table, but only can search either one only,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.