Autor Beitrag
TriphunEM
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 97



BeitragVerfasst: Mo 05.01.04 21:31 
Also, ich brauch ein Algoritmus für dieses Problem. Ich will ein Verzeichnislabyrinth anlegen
es sind zwei variablen gegeben.

variable 1 = Anzahl der Ordner in einem Ordner
variable 2 = Anzahl der Unterordner (Tiefe)

ganz wichtig die 2 variablen müßen auch variabel bleiben.

die entstehende verzeichnisstruktur sieht ungefähr so aus :

variable 1 = 3
variable 2 = 2

startorder ist z.b. c:\test\
dann geht los :

\1\1\
\1\2\
\1\3\
\2\1\
\2\2\
\2\3\
\3\1\
\3\2\
\3\3\

variable 1 = 3
variable 2 = 3

1\1\1\
1\1\2\
1\1\3\
1\2\1\
1\2\2\
1\2\3\
1\3\1\
1\3\2\
1\3\3\
2\1\1\
2\1\2\
2\1\3\
2\2\1
usw.

hat jemand sich schonmal mit dem problem beschäftigt.
Mir ist das zu hoch...
Wolff68
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 302
Erhaltene Danke: 1

WinXP home
D6 Prof
BeitragVerfasst: Di 06.01.04 12:38 
Was Du brauchst ist eine rekursive prozedur, die sich also je nach tiefe immer wieder selbst aufruft.

Hier mal ein Beispiel, das die Pfade in eine ListBox schreibt:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
procedure AddStr(PreStr: String; Ordner, Tiefe: Integer);
var
  i : Integer;
begin
  For i := 1 to Ordner Do begin
    IF Tiefe = 1 then // Eventuell ohne diese Abfrage
      Form1.ListBox1.Items.Add(PreStr+'\'+IntToStr(i));
    IF Tiefe > 1 then
      AddStr(PreStr+'\'+IntToStr(i),Ordner, Tiefe-1);
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  ListBox1.Clear;
  AddStr('C:\Test', 3, 3); // (Startverzeichnis, Ordneranzahl, Tiefe)
end;


* Wenn Du die Abfrage IF Tiefe = 1 then raus lässt bekommst Du auch die Zwischenerzeichnisse ausgegeben. Ist vielleicht sinnvoll, falls Du Probleme hast ein unter-unter Verzeichnis direkt anzulegen.
Also ERST MakeDir('\1') und DANN MakeDir('\1\1')

_________________
"Der Mensch ist nicht was er sich vorstellt oder wünscht zu sein, sondern das was andere in ihm sehen."
TriphunEM Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 97



BeitragVerfasst: Mi 07.01.04 15:34 
danke dir.