25. december 2004 - 15:07Der er
7 kommentarer og 1 løsning
vise filer i ikke undermapper ?
Denne viser alle txt filer i undermapperne hvordan får jeg den til også at vise txt filerne i den pågældende mappe incl undermapper ??
function TForm1.FindTxt(Path, Ext: string): TStringList; var SR: TSearchRec; begin Result := TStringList.Create; if FindFirst(Path + Ext, faArchive, SR) = 0 then try repeat Result.Add(Path + SR.Name); until FindNext(SR) <> 0; finally FindClose(SR); end; end;
procedure TForm1.Search(Path, Ext: string); var SR: TSearchRec; i: Integer; Strings: TStringList; begin Path := Path + '\'; if FindFirst(Path + '*.*', faDirectory, SR) = 0 then try repeat if ((SR.Attr and faDirectory) <> 0) and (SR.Name[1] <> '.') then begin Strings := FindTxt(Path + SR.Name + '\', Ext); try i := 0; while i < Strings.Count do begin ListBox1.Items.Add(Strings[i]); Inc(i); end; finally Strings.Free; end; end; until (FindNext(SR) <> 0); finally SysUtils.FindClose(SR); end; end;
procedure TForm1.Button1Click(Sender: TObject); begin ListBox1.Items.Clear; Search('C:', '*.txt'); end;
procedure TForm1.Search(Path, Ext: string); var SR: TSearchRec; i: Integer; Strings: TStringList; begin Path := Path + '\';
strings := FindTxt(Path, Ext); try i := 0; while i < Strings.Count do begin ListBox1.Items.Add(Strings[i]); Inc(i); end; finally strings.Free; end; if FindFirst(Path + '*.*', faDirectory, SR) = 0 then try repeat if ((SR.Attr and faDirectory) <> 0) and (SR.Name[1] <> '.') then begin Strings := FindTxt(Path + SR.Name + '\', Ext); try i := 0; while i < Strings.Count do begin ListBox1.Items.Add(Strings[i]); Inc(i); end; finally Strings.Free; end; end; until (FindNext(SR) <> 0); finally SysUtils.FindClose(SR); end; end;
du skal vist bare flytte den første if ind i repeat blokken
procedure TForm1.Search(Path, Ext: string); var SR: TSearchRec; i: Integer; Strings: TStringList; begin Path := Path + '\';
strings := FindTxt(Path, Ext); try i := 0; while i < Strings.Count do begin ListBox1.Items.Add(Strings[i]); Inc(i); end; finally strings.Free; end;
try repeat if FindFirst(Path + '*.*', faDirectory, SR) = 0 then if ((SR.Attr and faDirectory) <> 0) and (SR.Name[1] <> '.') then begin Strings := FindTxt(Path + SR.Name + '\', Ext); try i := 0; while i < Strings.Count do begin ListBox1.Items.Add(Strings[i]); Inc(i); end; finally Strings.Free; end; end; until (FindNext(SR) <> 0); finally SysUtils.FindClose(SR); end; end;
min fejl - det gå selvfølegelig ikke. Du skal bruge FindNext i loopet
procedure TForm1.Search(Path, Ext: string); var SR: TSearchRec; i: Integer; Strings: TStringList; begin Path := Path + '\';
strings := FindTxt(Path, Ext); try i := 0; while i < Strings.Count do begin ListBox1.Items.Add(Strings[i]); Inc(i); end; finally strings.Free; end;
if FindFirst(Path + '*.*', faDirectory, SR) = 0 then try repeat if FindNext(SR) = 0 then if ((SR.Attr and faDirectory) <> 0) and (SR.Name[1] <> '.') then begin Strings := FindTxt(Path + SR.Name + '\', Ext); try i := 0; while i < Strings.Count do begin ListBox1.Items.Add(Strings[i]); Inc(i); end; finally Strings.Free; end; end; until (FindNext(SR) <> 0); finally SysUtils.FindClose(SR); end; end;
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.