none
Alle Dateien aus einem Ordner und deren Unterordner ausgeben RRS feed

  • Frage

  • Hallo, ich möchte gerne alle Dateien aus einem Ordner in einer Listbox darstellen.

    Nun kann der ordner aber beliebig viele Unterordner haben.

    Um dies abfangen zu können, dachte ich an einen rekursive Aufruf mit directoryinfo und fileinfo.

    Leider stehe ich etwas auf dem schlauch und weis nicht genau wie ich das anstellen soll.

    Kann mir jemand helfen?

    Freitag, 15. März 2013 11:53

Antworten

  • Habe es schon hin bekommen und zwar so:

            private void PruefeAngebote(string Pfad)
            {
                System.IO.DirectoryInfo DirectoryAngebote = new System.IO.DirectoryInfo(Pfad);
                foreach (System.IO.DirectoryInfo d in DirectoryAngebote.GetDirectories())
                {
                    PruefeAngebote(d.FullName);
                }
                foreach (System.IO.FileInfo f in DirectoryAngebote.GetFiles())
                {
                    AngeboteClass NeuesAngebot = new AngeboteClass();
                    NeuesAngebot.Name = f.Name;
                    NeuesAngebot.VollerName = f.FullName;
                    Kunden[listBoxKunden.SelectedIndex].Angebote.Add(NeuesAngebot);
                }
                textBoxAnzahlAngebote.Text = Kunden[listBoxKunden.SelectedIndex].Angebote.Count.ToString();
            }

    • Als Antwort markiert Ionut Duma Dienstag, 26. März 2013 13:51
    Freitag, 15. März 2013 12:01

Alle Antworten

  • Hi,

    dafür gibt es <DirectoryInfo>.GetFiles( "*.*", SeachOption.AllDirectories ). Siehe dazu:

      http://msdn.microsoft.com/de-de/library/vstudio/ms143327.aspx


    Gruß, Stefan
    Microsoft MVP - Visual Developer ASP/ASP.NET
    http://www.asp-solutions.de/ - Consulting, Development
    http://www.aspnetzone.de/ - ASP.NET Zone, die ASP.NET Community

    Freitag, 15. März 2013 11:58
    Moderator
  • Habe es schon hin bekommen und zwar so:

            private void PruefeAngebote(string Pfad)
            {
                System.IO.DirectoryInfo DirectoryAngebote = new System.IO.DirectoryInfo(Pfad);
                foreach (System.IO.DirectoryInfo d in DirectoryAngebote.GetDirectories())
                {
                    PruefeAngebote(d.FullName);
                }
                foreach (System.IO.FileInfo f in DirectoryAngebote.GetFiles())
                {
                    AngeboteClass NeuesAngebot = new AngeboteClass();
                    NeuesAngebot.Name = f.Name;
                    NeuesAngebot.VollerName = f.FullName;
                    Kunden[listBoxKunden.SelectedIndex].Angebote.Add(NeuesAngebot);
                }
                textBoxAnzahlAngebote.Text = Kunden[listBoxKunden.SelectedIndex].Angebote.Count.ToString();
            }

    • Als Antwort markiert Ionut Duma Dienstag, 26. März 2013 13:51
    Freitag, 15. März 2013 12:01