Autor Beitrag
Vamos
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 44



BeitragVerfasst: Di 27.10.09 20:35 
Hallo Liebe Delphi Gemeinde,

ich muss meine Frage noch einmal separiert von Threads die nur das Thema ankratzen stellen.

Ich schreibe z.Zt. ein Programm, welches Dateien aus bestimmten Ordnern anzeigen (später löschen - macht beim Testen nicht ganz so viel Spaß ;) ) soll.

Klappt soweit auch alles wunderbar, NUR die Filterbdeingung mit dem Erstellungsdatum scheint nicht zu greifen... Bin am verzweifeln, irgendwas überseh ich nur was?

Hier zum nachvollziehen mal der Kot : )

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:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
function GetCreationTimeOfFile(const AFileName: string): TDateTime;
var
  SR: TSearchRec;
  SystemTime: TSystemTime;
  NewCreationTime: TFileTime;
begin
  Result:=0;
  if FindFirst(AFileName, faAnyFile, SR)=0 then
  try
   if (Windows.FileTimeToLocalFiletime(SR.FindData.ftCreationTime, NewCreationTime) and
           Windows.FileTimeToSystemTime(NewCreationTime, SystemTime)) then
    Result:=Encodedate(SystemTime.wYear,
                       SystemTime.wMonth,
                        SystemTime.wDay) +
            Encodetime(SystemTime.wHour,
                       SystemTime.wMinute,
                       SystemTime.wSecond,
                       SystemTime.wMilliseconds);
  finally
   SysUtils.FindClose(SR)
  end;
end;

procedure TForm1.Beenden1Click(Sender: TObject);
begin
close;
end;

procedure GetFilesInDirectory(Directory: stringconst Mask: string;
                              List: TStrings;
                              WithSubDirs, ClearList: Boolean);

procedure ScanDir(const Directory: string);
var
  SR: TSearchRec;
  a: TDateTime;
  Lnewdate: TLabel;
  Etest: TEdit;
begin
Lnewdate.caption := DateToStr(a);
  if FindFirst(Directory + Mask, faAnyFile and not faDirectory, SR) = 0 then try
    repeat
      begin     
      if GetCreationTimeOfFile(Directory + SR.Name) > a then        //Eigentlich = a stehen, nur dann bringt er NICHTS, Datei von heute besteht...
      List.Add(Directory + SR.Name)
      end
    until FindNext(SR) <> 0;
  finally
    FindClose(SR);
  end;

  if WithSubDirs then begin
    if FindFirst(Directory + '*.*', faAnyFile, SR) = 0 then try
      repeat
        if ((SR.attr and faDirectory) = faDirectory) and
           (SR.Name <> '.'and (SR.Name <> '..'then
          ScanDir(Directory + SR.Name + '\');
      until FindNext(SR) <> 0;
    finally
      FindClose(SR);
    end;
  end;
end;

begin
  List.BeginUpdate;
  try
    if ClearList then
      List.Clear;
    if Directory = '' then Exit;
    if Directory[Length(Directory)] <> '\' then
      Directory := Directory + '\';
    ScanDir(Directory);
  finally
    List.EndUpdate;
  end;
end;


Danke vielmals!
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Di 27.10.09 20:49 
Hallo,

zu der lokalen Variable a: : TDateTime; fehlt die Initialisierung.

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
Vamos Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 44



BeitragVerfasst: Di 27.10.09 21:06 
user profile iconLannes hat folgendes geschrieben Zum zitierten Posting springen:
Hallo,

zu der lokalen Variable a: : TDateTime; fehlt die Initialisierung.


Vielen Dank für die schnelle Antwort, aber ist die Variable nicht initialisiert? Also deklariert ist Sie und ich dachte durch Lnewdate.caption := DateToStr(a); würde ich sie initialisieren... Tue ich das nicht? Was fehlt? Danke im Voraus.
Hobby-Programmierer
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 238
Erhaltene Danke: 4

Win XP Pro, Vista Ultimate Trial :o)
D6 Pro, D7 Pro, Turbo, XE SE
BeitragVerfasst: Di 27.10.09 21:44 
So hab das jetzt mal von hier umgeschrieben. www.delphi-forum.de/....php?p=582688#582688
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:
52:
53:
54:
55:
56:
procedure GetFilesInDirectory( Directory: string;
                              const Mask: string;
                              const ATime: TDate;
                              List: TStrings;
                              WithSubDirs, ClearList: Boolean);


procedure ScanDir(const Directory: string);
var
  SR: TSearchRec;
  SystemTime: TSystemTime;
  FN: string;  // FileName
  FS: String// FileSize
  FD: TDate; // FileDate
begin
  if FindFirst(Directory + Mask, faAnyFile and not faDirectory, SR) = 0 then
  try
    repeat
      if FileTimeToSystemTime(sr.FindData.ftCreationTime, SystemTime) then
        FD:= SystemTimeToDateTime(SystemTime)
       else
        FD:= 0.0;
       FN:= Directory + SR.Name;
       FS:= inttostr(sr.Size);
       if FD > ATime then // Dateierstellungszeit > Suchzeit
         List.Add(FN+ ' # '+ FS+ ' # '+ DateToStr(FD));
    until FindNext(SR) <> 0;
   finally
    FindClose(SR);
  end;

  if WithSubDirs then begin
    if FindFirst(Directory + '*.*', faAnyFile, SR) = 0 then try
      repeat
        if ((SR.attr and faDirectory) = faDirectory) and
           (SR.Name <> '.'and (SR.Name <> '..'then
          ScanDir(Directory + SR.Name + '\');
      until FindNext(SR) <> 0;
    finally
      FindClose(SR);
    end;
  end;
end;

begin
  List.BeginUpdate;
  try
    if ClearList then
      List.Clear;
    if Directory = '' then Exit;
    Directory:= IncludeTrailingPathDelimiter(Directory);
    ScanDir(Directory);
  finally
    List.EndUpdate;
  end;
end;
Zeigt Dateien die in den letzten 10 Tage erstellt wurden
ausblenden Delphi-Quelltext
1:
GetFilesInDirectory('p:''*.*', (now -10), memo1.Lines, true, true);					


Zuletzt bearbeitet von Hobby-Programmierer am Di 27.10.09 21:51, insgesamt 1-mal bearbeitet
Hobby-Programmierer
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 238
Erhaltene Danke: 4

Win XP Pro, Vista Ultimate Trial :o)
D6 Pro, D7 Pro, Turbo, XE SE
BeitragVerfasst: Di 27.10.09 21:49 
user profile iconVamos hat folgendes geschrieben Zum zitierten Posting springen:
user profile iconLannes hat folgendes geschrieben Zum zitierten Posting springen:
Hallo,

zu der lokalen Variable a: : TDateTime; fehlt die Initialisierung.


Vielen Dank für die schnelle Antwort, aber ist die Variable nicht initialisiert? Also deklariert ist Sie und ich dachte durch Lnewdate.caption := DateToStr(a); würde ich sie initialisieren... Tue ich das nicht? Was fehlt? Danke im Voraus.
ausblenden Delphi-Quelltext
1:
2:
a:= 0.0;
Lnewdate.caption := DateToStr(a);
Vamos Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 44



BeitragVerfasst: Di 27.10.09 21:52 
Vielen Dank Dir!

mein Aufruf sieht so aus:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
procedure TForm1.BdelClick(Sender: TObject);
var s1, s2, s3, s4, s5, s6, s7, sLoeschlog :string;
a: TDateTime;
f: textfile;
begin
  Lheute.Caption := DateToStr (date);
  a:=StrToInt(EAlter.text);
  Lnewdate.caption :=DateToStr(date-a);;
 

    s1 := EPath1.text;
      GetFilesInDirectory(s1, '*.*', (now), Listbox1.Items, True, True); //Eigentlich now-a
        ProgressBar1.position:=ProgressBar1.position+14;
...


Leider sagt er mir da inkompatibe Typen...
Hobby-Programmierer
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 238
Erhaltene Danke: 4

Win XP Pro, Vista Ultimate Trial :o)
D6 Pro, D7 Pro, Turbo, XE SE
BeitragVerfasst: Di 27.10.09 22:00 
Moderiert von user profile iconNarses: Komplett-Zitat des letzten Beitrags entfernt.

Du vermischt aber auch alles. Maxh doch erstmal eins nach dem anderen
[edit] dir ist aber bewusst das er jetzt nur Dateien anzeigt, die Heute erstellt wurden?
Vamos Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 44



BeitragVerfasst: Di 27.10.09 22:15 
Moderiert von user profile iconNarses: Komplett-Zitat des letzten Beitrags entfernt.

Habs rausgefunden, hatte oben was vergessen :autsch:

Vielen Dank!!! Aber irgendwas stimmt noch nicht... obwohl ich das geändert habe:

ausblenden Delphi-Quelltext
1:
if FD >= ATime then					


Findet er die heutigen Dateien nur, wenn ich now-1 rechne... O.o
Hobby-Programmierer
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 238
Erhaltene Danke: 4

Win XP Pro, Vista Ultimate Trial :o)
D6 Pro, D7 Pro, Turbo, XE SE
BeitragVerfasst: Di 27.10.09 22:22 
ausblenden Delphi-Quelltext
1:
if FD > (ATime -1then					

Ein wenig mitdenken musst du aber auch noch. C & P allein reicht net :roll:
Vamos Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 44



BeitragVerfasst: Di 27.10.09 22:50 
user profile iconHobby-Programmierer hat folgendes geschrieben Zum zitierten Posting springen:
ausblenden Delphi-Quelltext
1:
if FD > (ATime -1then					

Ein wenig mitdenken musst du aber auch noch. C & P allein reicht net :roll:


Glaube bin kurz davor mir meinen gesamten Sourcecode zu versauen : ( *wenn man das noch kann*

Jetzt zeigt er mit NUR noch Einträge von heute...

ausblenden Delphi-Quelltext
1:
2:
3:
4:
 
if FD > (ATime-1then // Dateierstellungszeit > Suchzeit
         List.Add(FN+ ' # '+ FS+ ' # '+ DateToStr(FD));
    until FindNext(SR) <> 0;


ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
procedure TForm1.BdelClick(Sender: TObject);
var s1, s2, s3, s4, s5, s6, s7, sLoeschlog :string;
a, b: TDateTime;
f: textfile;
begin
  Lheute.Caption := DateToStr (date); //ok
  a:=StrToint(EAlter.text);          //Dateien die Älter als A Tage sind
  Lnewdate.caption :=DateToStr(date-a);  //neues Datum = Datum-Tage


    s1 := EPath1.text;
      GetFilesInDirectory(s1, '*.*', (now-a), Listbox1.Items, True, True);
        ProgressBar1.position:=ProgressBar1.position+14;
    s2 := EPath2.text;
      GetFilesInDirectory(s2, '*.*', (now-a), Listbox2.Items, True, True);
        ProgressBar1.position:=ProgressBar1.position+14;


Irgendwo sag ich dem Programm das ja, aber wo?

Oben nimmt er nur Dateien, die größer, sprich Älter als heute sind.
Unter m.E. auch.

Also bei EAlter = 0 müsste ich aber ALLE Dateien inkl der von heute sehen, bei EAlter = 1 nur noch die von Gestern und davor .. usw.

Bitte nochmal um Rat
Vamos Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 44



BeitragVerfasst: Di 27.10.09 23:17 
user profile iconHobby-Programmierer hat folgendes geschrieben Zum zitierten Posting springen:
ausblenden Delphi-Quelltext
1:
if FD > (ATime -1then					

Ein wenig mitdenken musst du aber auch noch. C & P allein reicht net :roll:


Da war mein und Dein Denkfehler. Wenn FD > Heute, dann gibt es sie nich gar nicht, wenn FD < Heute, liegt sie in der Vergangenheit..

jetzt gehts jedenfalls, nochmals vielen Dank!
Hobby-Programmierer
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 238
Erhaltene Danke: 4

Win XP Pro, Vista Ultimate Trial :o)
D6 Pro, D7 Pro, Turbo, XE SE
BeitragVerfasst: Mi 28.10.09 00:02 
(FD > Heute -1) ist logischerweise das gleiche wie (FD = Heute)
Zitat:
Also bei EAlter = 0 müsste ich aber ALLE Dateien inkl der von heute sehen, bei EAlter = 1 nur noch die von Gestern und davor .. usw.
Falsch. Bist du sicher das du die Programmlogik richtig verstanden hast?
Bei Now - 0 zeigt er nur die Dateien von heute,
bei Now - 1 nur die Dateien von Gestern und heute ...
Es werden die Dateien angezeigt die am = > ATag bis heute erstellt wurden.

Wenn du eine andere Logik brauchst, musst du das natürlich umstellen
Einloggen, um Attachments anzusehen!