Autor Beitrag
Flamefire
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1207
Erhaltene Danke: 31

Win 10
Delphi 2009 Pro, C++ (Visual Studio)
BeitragVerfasst: Do 30.10.08 14:14 
Ich habe meinen Code von TsearchRec auf die Win-API umgeschrieben, damit er schneller ist:
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
procedure TSuchThread.ScanDir(Ordner:TOrdner;const Directory: string);

function BackupDir(const s:String): Boolean;
begin
  If(BackupPathLength <= Length(s)) then
    Result := CompareMem(PChar(s),PChar(BackupPath),BackupPathLength)
  else Result:=false;
end;

var
  tmp:TOrdner;
  itmp:Cardinal;
  iSize,iDate:Int64;
  hFindFile:THandle;
  wfd:TWin32FindData;
begin
  If(not Terminated) then begin
    ZeroMemory(@wfd, sizeof(wfd));
    wfd.dwFileAttributes := FILE_ATTRIBUTE_NORMAL;
    hFindFile := FindFirstFile(pointer(Directory + '*.*'), wfd);
    if hFindFile <> 0 then
    try
      repeat
          If ((wfd.dwFileAttributes and faDirectory) = faDirectory) then begin
            if (string(wfd.cFileName) <> '.'and (string(wfd.cFileName) <> '..'then
              If(FSubDir) and (not BackupDir(wfd.cFileName)) then begin
                tmp:=TOrdner.Create(wfd.cFileName,Ordner);
                ScanDir(tmp,Directory + wfd.cFileName + '\');
                Inc(FiOrdner);
              end;
          end else begin
            iSize :=  wfd.nFileSizeLow;
            PCardinal(Cardinal(@iSize) + SizeOf(Cardinal))^ := wfd.nFileSizeHigh;
            iDate := wfd.ftLastWriteTime.dwLowDateTime;
            PCardinal(Cardinal(@iDate) + SizeOf(Cardinal))^ := wfd.ftLastWriteTime.dwHighDateTime;
            Ordner.Dateien.Add(wfd.cFileName,iSize,iDate);
            Inc(FiDateien);
          end;
      until FindNextFile(hFindFile, wfd) = False;
    finally
      Windows.FindClose(hFindFile);
    end;
    Ordner.Dateien.Sort(true);
    Ordner.Ordner.Sort(@CompareOrdner);
    itmp:=GetTickCount;
    if(GetTickDiff(FTime,itmp)>80then begin
      Synchronize(SyncStatus);
      FTime:=itmp;
    end;
  end;
end;

2 Fragen:
1) Habe ich dabei was übersehn zu ändern?
2) Sieht jemand noch weitere Optimierungsmöglichkeiten (Ist schon sehr schnell =) )


Zuletzt bearbeitet von Flamefire am Do 30.10.08 14:30, insgesamt 1-mal bearbeitet
j.klugmann
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Do 30.10.08 14:22 
Sieht schon gut aus! :zustimm: Aber warum ist deine Funktion nicht Rekursiv oder habe ich
etwas übersehen?
Mehr kann ich leider grade nicht sagen.Der Arzt ruft! :shock:
Flamefire Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1207
Erhaltene Danke: 31

Win 10
Delphi 2009 Pro, C++ (Visual Studio)
BeitragVerfasst: Do 30.10.08 14:31 
die funktion ist doch rekursiv

guck mal in den zweig, wo der ordner behandlet wird
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Fr 31.10.08 11:59 
Such mal nach den SearchUtils hier im Forum ... die sind darauf optimiert schnell zu sein ;-)

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
Flamefire Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1207
Erhaltene Danke: 31

Win 10
Delphi 2009 Pro, C++ (Visual Studio)
BeitragVerfasst: Fr 31.10.08 22:14 
gesucht und kein treffer außer diesem thread!
hast du nen link?
Chryzler
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1097
Erhaltene Danke: 2



BeitragVerfasst: Fr 31.10.08 22:58 
Flamefire Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1207
Erhaltene Danke: 31

Win 10
Delphi 2009 Pro, C++ (Visual Studio)
BeitragVerfasst: Sa 01.11.08 00:11 
hmm...find da auch nichts andres als in meinem code (außer die kommunikation mit messages,die aber das suchen nicht weiter beeinträchtigt)...
na gut dann geht ebn nicht mehr
danke trotzdem