By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,333 Members | 1,070 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,333 IT Pros & Developers. It's quick & easy.

DirectoryInfo.GetFiles -> from all subfolders

P: n/a
Hi
I have folder

Music

with subfolder

Rock

with subfolder

Kult

folder tree looks like this:

Music
-Rock
-Kult

and in folders called Kult and Rock I have txt files.

Do you have code, with directoryinfo, which can show names of all
files?? from first subfolder called Rock and from second called Kult? I
found loops by which i can display files from first subfolder Rock but
files in Kult isn't shown.

Sorry for my english, but you know... still learning

Thx Mrozu

Apr 6 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a
i forgot. VB.NET 2003

Mrozu

Apr 6 '06 #2

P: n/a
You have to use recursive loops, where you're calling the function, from
the function itself.

e.g:

Public Function FindFiles(ByVal Path As String) As Boolean
Dim Directories As New IO.DirectoryInfo(Path)
Dim Directory As IO.DirectoryInfo

For Each Directory In Directories.GetDirectories
ListBox1.Items.Add(Directory.Name)

If Directory.GetDirectories.Length > 0 Then
FindFiles(Directory.FullName)
End If
Next
End Function

Should work, but not tested :)

- Tank

Mrozu wrote:
i forgot. VB.NET 2003

Mrozu

Apr 6 '06 #3

P: n/a
great but it displaies only folders'es names. but how rebuild it for
files'es names in those folders?

Thx Mrozu

Apr 6 '06 #4

P: n/a
The recusive function will need to provide the filenames first with the
GetFiles method feeding a For Each loop to an instance of the FileInfo
class.

Apr 6 '06 #5

P: n/a
Easy, you could do this:

Public Function FindFiles(ByVal Path As String) As Boolean
Dim Directories As New IO.DirectoryInfo(Path)
Dim Directory As IO.DirectoryInfo
Dim File As IO.FileInfo

For Each Directory In Directories.GetDirectories
For Each File In Directory.GetFiles
ListBox1.Items.Add(File.Name)
Next

If Directory.GetDirectories.Length > 0 Then
FindFiles(Directory.FullName)
End If
Next
End Function

- Tank

Mrozu wrote:
great but it displaies only folders'es names. but how rebuild it for
files'es names in those folders?

Thx Mrozu

Apr 6 '06 #6

P: n/a
Thx Tank it works great:D

Mrozu

Apr 7 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.