How to recursively get files from subdirectory

  • Thread starter Thread starter Anil Gupte
  • Start date Start date
A

Anil Gupte

Hi all! Hope you can help me.

I want to find all files matching a wildcard in all subdirectories. Is
there a quick way to do that? For example in DOS I can go dir *.txt /s and
it will find all txt files in the current directory and all directories
below that. Is there a VB function that will do that? The other choice is
to create some complicated recursive function that lists each directory,
stores the names of the subdirectories and then runs the function again on
each of those.

Any advice appreciated.

TIA,
 
Anil,

You might try the My.Computer.FileSystem.GetFiles method with the
SearchAllSubDirectories search option.

Kerry Moorman
 
Hi all!  Hope you can help me.

I want to find all files matching a wildcard in all subdirectories.  Is
there a quick way to do that?  For example in DOS I can go dir *.txt /s and
it will find all txt files in the current directory and all directories
below that.  Is there a VB function that will do that?  The other choice is
to create some complicated recursive function that lists each directory,
stores the names of the subdirectories and then runs the function again on
each of those.

http://groups.google.com/group/micr...=en&lnk=gst&q=zacks+getfiles#c6135c3c82347084
 
Better yet, take a look at the System.IO.Directory class. There are
additional, useful, methods in this class.

Mike.
 
Is this in .Net 2003. A seach for SearchAllSubDirectories revealed 0
entries in Help.

Thanx,
 
Help file keeps talking about GetFileSystemInfos and how you can get all
subdirs ad files, but it does not go into sudirectories. I tried this
example from help and it only gave me one level.

Imports System
Imports System.IO

Public Class Test
Public Shared Sub Main()
' Specify the directories you want to manipulate.
Dim di As DirectoryInfo = New DirectoryInfo("c:\")
Try
' Get only subdirectories that contain the letter "p."
Dim dirs As FileSystemInfo() = di.GetDirectories("*p*")
Console.WriteLine("Number of directories with a p: {0}",
dirs.Length)
Dim diNext As DirectoryInfo

' Count all the files in each subdirectory that contain the
letter "e."
For Each diNext In dirs
Console.WriteLine("The number of files and directories " + _
"in {0} with an e is {1}", diNext, _
diNext.GetFileSystemInfos("*e*").Length)
Next
Catch e As Exception
Console.WriteLine("The process failed: {0}", e.ToString())
End Try
End Sub
End Class

Thanx,
 
Anil,

No, with .Net 2003 you will need to do a good bit more work to get what you
want.

Kerry Moorman
 
Thanx for the link. My VB.Net 2003 seems to choke on these

Private _Files As List(Of String)
Private _Folders As List(Of String)

I get "Array bounds cannot appear in type specifiers."

Is this too new or too old for .Net 2003?

Thanx,
--
Anil Gupte
www.keeninc.net
www.icinema.com

Hi all! Hope you can help me.

I want to find all files matching a wildcard in all subdirectories. Is
there a quick way to do that? For example in DOS I can go dir *.txt /s and
it will find all txt files in the current directory and all directories
below that. Is there a VB function that will do that? The other choice is
to create some complicated recursive function that lists each directory,
stores the names of the subdirectories and then runs the function again on
each of those.

http://groups.google.com/group/micr...=en&lnk=gst&q=zacks+getfiles#c6135c3c82347084
 
..Net 2003 (1.1) doesn't support the parameterized lists. These are
"generics" and are first supported in .Net 2.0 (VS 2005).

Mike.
 
Back
Top