Re: Recursive Reading : Corrected

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



On Jun 14, 4:51 pm, "Benjamin Vigneaux" <b...@xxxxx> wrote:
The Folders looked all wrong with the formatting I gave thm... it could
cause confusion..so i'm reposting with a different fomat:
===================================

Hey everyone!

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

Example:

rootFolder (Folder1 "(" Folder2 *(* Folder3( F3File1, F3File2)
F2File1,F2File2* )* F1File1,F1File2 ")" RFFile1, RFFile2 )

It might take you a while but you'll probably see how the folder tree is
structured... the " * characters with the brackets are just to tell the
difference between them, reference.

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 F2File2 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(NextFolder);
}

}

Thnx in advance!

Benjamin Vigneaux,


Not sure but

protected void MessContents(DirectoryInfo root)
{

// when root =Folder3 , There are are not directories

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

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

MessContents(NextFolder);
}

}



I think this could help. not tested it though

foreach (FileInfo fi in di.GetFiles())
{
if ((fi.Attributes & FileAttributes.Directory) !=
FileAttributes.Directory)
{
//is file
}
else if ((fi.Attributes & FileAttributes.Directory) ==
FileAttributes.Directory)
{
//recurse
}
}
.



Relevant Pages

  • Using a custom attribute in aspx pages
    ... Public Class SomeClass ... ... Using reflection, I am able to find all attributes within the App_Code ... foreach { ... because they don't reside within the App_code folder, ...
    (microsoft.public.dotnet.languages.csharp)
  • ContextSwitchDeadlock
    ... It navigates a folder tree of N-Levels and it moves all the files from each folder to the root folder, ... foreach ) ... The CLR has been unable to transition from COM context 0x1f6050 to COM context 0x1f61c0 for 60 seconds. ... The thread that owns the destination context/apartment is most likely either doing a non pumping wait ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Add images recursively to tablelist cells?
    ... $tbl cellconfigure 0,$row -image folder # Cellconfigure the table at column 0 and at specified row to the image of a folder. ... Since your list only has a single value the foreach will only # iterate once. ... The foreach loop now terminates. ...
    (comp.lang.tcl)
  • how to get more detail while enum the network adapters?
    ... I try to use the shell32 to enum the network adapters that installed on ... Shell32.Folder folder; ... foreach ) ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Page and Images not found on Localhost
    ... I didn't know that even images could be declared as server controls. ... which may not have been declared as a server control. ... I designated the "project" folder as an application in IIS. ... is the root for anything under it. ...
    (microsoft.public.dotnet.framework.aspnet)