Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Programmieren allgemein (https://www.delphipraxis.net/40-programmieren-allgemein/)
-   -   GetFILEs mit INterruption .. (https://www.delphipraxis.net/204897-getfiles-mit-interruption.html)

wschrabi 11. Jul 2020 19:06

GetFILEs mit INterruption ..
 
Hi Leute,
ich hab das hier gelesen und komm damit nicht klar: http://codeverge.com/embarcadero.del...getfil/1068298


Ich will auch das root dir nicht durchsuchen. Und hab diesen CODE:

Kann mir jmd sagen, wo der Fehler liegt?
DANKE


Delphi-Quellcode:
procedure Tform1.scandir(mypath: string);
var
   path : string;
   Predicate : function (const Path: string; const SearchRec: TSearchRec): boolean;
   begin
     if Path=extractfilepath(Savedialog12.filename) then Abort;
   end;
   
Begin
    try
       for Path in TDirectory.GetFiles( mypath,'*.*',TSearchOption.soAllDirectories,Predicate) do
         begin
           Listbox2.Items.Add(Path);
           Memo15.Lines.Add(Path);
         end;

    except
      on E: EAbort do
        begin
        // canceled ...
        writelogmemo('Read all aborded ! ');
        end;    
     end;  
end;
Mein Call in hörere Routine:
Delphi-Quellcode:

Begin
    listbox2.Clear;
    memo15.Clear;

    mypath:=extractfilepath(savedialog12.filename)+extractfilepath(stringreplace(
      stringreplace(risfn,'/','\',[rfreplaceall]),'internal-pdf:\\','',[rfreplaceall]));
    writelogmemo('PLEASE WAIT: Reading Files form: '+mypath);

    scandir(mypath);

    writelogmemo('Read all Files done: Count: '+inttostr(Memo15.Lines.count));
end;

himitsu 11. Jul 2020 20:50

AW: GetFILEs mit INterruption ..
 
Wie wäre es, wenn man auf den Compiler hört, der hier hoffentlich sich über das nicht initialisierte Result beschwert?

Und warum Abort, wenn .... rate mal wofür das Result ist. :zwinker:
OK, Result um den einzelnen Eintrag zu filtern und Abort zum Komplettabbruch, aber dennoch muß Result gesetzt sein. :stupid:

Delphi-Quellcode:
Path = mypath
ist das Rootverzeichnis,
aber dennoch willst du ja die Verzeichnisse darin dennoch haben, also
Delphi-Quellcode:
Result := (SearchRec.Attr and faDirectory <> 0) or (Path <> mypath);


Alle Zeitangaben in WEZ +1. Es ist jetzt 22:32 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz