473,385 Members | 1,409 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,385 software developers and data experts.

Get All FileNames in subfolders - For new VB'ers

Expanding a basic recursive method I got from this news group for getting all
files in a directory and it's subdirectories, I thought someone might be
interested in this (it's pretty simple but works well). The filenames
matching the searchpattern (nothing returns all) are returned in the List
arraylist. Note that the searchpattern should be input in lower case to be
sure it works with all option compares. If returnpath is true, the full path
and filename are returned. If chksubdir is true, files in the subdirectory
are returned as well.

Just thought someone new to VB might be interested.

Private Sub ListFiles(ByRef list As ArrayList, ByVal sPath As String, ByVal
searchpattern As String, ByVal returnpath As Boolean, ByVal chksubdir As
Boolean)
Dim di As System.IO.DirectoryInfo
Try
di = New System.IO.DirectoryInfo(sPath)
For Each fi As System.IO.FileInfo In di.GetFiles
If fi.Name.ToLower Like searchpattern OrElse searchpattern =
Nothing Then
If returnpath Then list.Add(fi.FullName) Else
list.Add(fi.Name)
End If
Next
If chksubdir Then
For Each diSub As System.IO.DirectoryInfo In di.GetDirectories
ListFiles(list, diSub.FullName, searchpattern,
returnpath, chksubdir)
Next
End If
Catch ex As Exception
list = Nothing
errmsg = ex.Message
errno = Err.Number
End Try
End Sub
--
Dennis in Houston
Nov 21 '05 #1
0 927

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

Similar topics

3
by: Enigman O'Maly | last post by:
With VB.NET, or Visual Fred the current thing, what future, if any, does "classic" Visual Basic have? Also, is VBA going to become VNETA, or has it done so already?
15
by: Peter | last post by:
I really can't understand why you still use it or why you started using it in the first place.
16
by: Terry | last post by:
Hi, I need some feedback. We are converting to .Net and we are trying to decide on whether to use VB.net or C#.net. As far as our current systems, they will probably be rewritten in ASP.Net. I...
43
by: Spare Change | last post by:
This is a recommendation to Microsoft. VB.net and c# are almost exactly equivalent. I know why Microsoft invented VB.net -- to wean old style VB6 scripters into a true OO world: .Net. But...
30
by: Chad Z. Hower aka Kudzu | last post by:
I need to provide a series of demos for an assembly. There are potentialy several dozen of them. None of them are very complex, however maintaining two versions of them will be very maintainance...
28
by: smith | last post by:
The intense off-topic VB6/VB.Net thread "Where is the Key in Treeview.Net" (started Dec 2 2004 and cross-posted to every VB group under the sun) really got me to thinking. And that thinking got...
1
by: Phill W. | last post by:
I'm still having trouble trying to generate MSDN-style documentation for the classes and controls I've written and, because traffic in the SourceForge forums seems to have completely dried up, I...
10
by: Tina | last post by:
In vb we say.... Dim theRow As dsLogin.CustLoginRow theRow = DsLogin1.CustLogin.Rows(0) If I try to say the following in C# it says I can't do an implicit conversion... ...
14
by: Siv | last post by:
Hi, Just busily coding away and removed a procedure from my code and all of a sudden an error came up miles away from the location of the piece of code I removed and it relates to the XML...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.