Recursive Reading

B

Benjamin Vigneaux

Hey everyone!

Basicaly what i'm doing is showing MessageBoxes with the contents of a
folder tree...

Example:

rootFolder -> Folder1 -> Folder2 -> Folder3 -> F3File1
RFFile1 F1File1 F2File1
F3File2
RFFile2 F1File2 F2File2
F3File3
RFFile3 F1File3 F2File3

RF"name" or F#"name" is to tell you in wich folder a file is, it's just for
reference, RFFile1,for example, is in the Root Folder, and F2File3 is in
Folder2

My problem is: With the folowing code I can only get to the contents of
Folder2 which are Folder3, F2File1 etc etc...
but I can't get to the contents within Folder3.... could anyone suggest me
what to do? (I know it's quite simple, but i've been so many hours looking
at it that I can't see it!


protected void MessContents(DirectoryInfo root)
{

foreach (DirectoryInfo NextFolder in root.GetDirectories())
{
MessageBox.Show(NextFolder.Name);

foreach (FileInfo NextFile in root.GetFiles())
{
MessageBox.Show(NextFile.Name);
}

MessContents(CarpetaSiguiente);
}


}

Thnx in advance!

Benjamin Vigneaux,
 
P

parez

[...]
rootFolder -> Folder1 -> Folder2 -> Folder3 -> F3File1
RFFile1 F1File1 F2File1 F3File2
RFFile2 F1File2 F2File2 F3File3
RFFile3 F1File3 F2File3

Just FYI: if you're going to try to use text to line things up, you need
to write your post using a fixed-pitch font. Using a proportional-pitch
font, then there's no way to ensure that the recipient sees what you see.

In other words, I have little idea what the above is supposed to
represent. Nothing lines up on my screen.
[...]
My problem is: With the folowing code I can only get to the contents of
Folder2 which are Folder3, F2File1 etc etc...
but I can't get to the contents within Folder3.... could anyone suggest
me what to do? (I know it's quite simple, but i've been so many hours
looking at it that I can't see it!

What isn't working for you? The code you posted doesn't even seem like it
would compile, as the argument you're passing to "MessContents" from
within "MessContents" doesn't appear to be declared anywhere.

It's possible that your question can be answered without a _complete_ code
sample (even though complete samples are generally better), but it should
at least be a code sample that is at least reasonably self-evident. What
you posted isn't.

For what it's worth, other than the fact that the argument you're passing
to "MessContents" seems completely random, the code you posted seems
reasonable. In other words, probably your problem is just that you're not
passing the right thing to the method. It seems like you ought to be
passing "NextFolder", rather than whatever "CarpetaSiguiente" represents.

Pete

CarpetaSiguiente is next folder in spanish.;)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top