473,320 Members | 2,048 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,320 software developers and data experts.

DirectoryInfo.GetFiles -> from all subfolders

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
6 13844
i forgot. VB.NET 2003

Mrozu

Apr 6 '06 #2
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
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
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
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
Thx Tank it works great:D

Mrozu

Apr 7 '06 #7

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

Similar topics

2
by: Demetri | last post by:
Using the GetFiles method of the DirectoryInfo instance one can pass in a search pattern of string type. For example: DirectoryInfo di = new DirectoryInfo("C:\temp"); FileInfo fi =...
4
by: Pluto | last post by:
Hi, I want to get a list of files matching certain extensions, such as "*.jpg;*.gif" (i.e. all files ending with .jpg and .gif). I was using DirectoryInfo.GetFiles(string) method....
0
by: Glenn Venzke | last post by:
I have an aspx page that is set up to copy backed-up DB files from a shared directory to a local folder. For some reason, it is being denied access to the network share. I have the web app running...
8
by: Lyners | last post by:
I have code that retrieves all of the file names within a directory. After retriving them, I display the information in a datagrid. What I would like to do is add an extra output column on the...
3
by: xenophon | last post by:
This following innocuous code: System.IO.DirectoryInfo fff = new System.IO.DirectoryInfo(); System.IO.FileInfo ppp = fff.GetFiles( Request.MapPath(".") ); for( int ccc=0 ; ccc < ppp.Length ;...
5
by: CJ Taylor | last post by:
Hey Everyone, Sorry haven't been around to answer questions as much as usual (or at all for that matter) just been engrossed in a project. Anyways, dealing with an issue using...
13
by: Tom Scales | last post by:
OK, I admit, I am not a VB.NET expert and am still learning, but have run into an annoying problem. I'm writing a program that has to search the file system and therefore processes large numbers...
1
by: jobs | last post by:
Say I only have a single file I want to get information on. How can I adapt this code? Dim dr As DataRow Dim fi As FileInfo Dim dir As New DirectoryInfo(filename) Dim dt As New DataTable...
2
by: RodneyAnonymous | last post by:
Hello everyone. I'm working on a simple utility that lists all files in a given directory with a given extension and outputs the results to a text file. I'm encountering issues while testing where...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.