Autor Beitrag
Hendi48
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 271



BeitragVerfasst: Mi 04.06.08 18:42 
Hallo, ich habe ein kleines Problem:
ich lasse mir mit folgender Funktion alle Dateien mit Größe und Attribut in einen string laden.
Allerdings ist das Attribut bei Dateien immer FILE_ATTRIBUTE_ARCHIVE, also habe ich da einfach 'Datei' hingeschrieben. Nun werden aber manche Ordner auch als Datei bezeichnet, weil sie archiviert werden können. Haben die Ordner noch ein zweites Attribut, welches besagt ob es ein Ordner oder eine Datei ist?

ausblenden 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:
function getFull(path: string): string;
var
  SR: TSearchRec;
  sAttr: string;
begin
  //.
  FindFirst(path + '*.*', faAnyFile, SR);
  //..
  FindNext(SR);

  repeat
    case SR.FindData.dwFileAttributes of
      FILE_ATTRIBUTE_ARCHIVE: sAttr := 'Datei';
      FILE_ATTRIBUTE_COMPRESSED: sAttr := 'Datei [Komprimiert]';
      FILE_ATTRIBUTE_DIRECTORY: sAttr := 'Ordner';
      FILE_ATTRIBUTE_HIDDEN: sAttr := 'Datei [Versteckt]';
      FILE_ATTRIBUTE_NORMAL: sAttr := 'Datei';
      FILE_ATTRIBUTE_OFFLINE: sAttr := 'Datei [Offline]';
      FILE_ATTRIBUTE_READONLY: sAttr := 'Datei [Schreibgeschützt]';
      FILE_ATTRIBUTE_SYSTEM: sAttr := 'Systemdatei';
      FILE_ATTRIBUTE_TEMPORARY: sAttr := 'Temporäre Datei';
    end;
    Result := Result + SR.Name + '@@' + IntToStr(SR.Size) + '@@' + sAttr + sLineBreak;
  until FindNext(SR) <> 0;

  SysUtils.FindClose(SR);
end;


Gruß,
Hendi
Xentar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2077
Erhaltene Danke: 2

Win XP
Delphi 5 Ent., Delphi 2007 Prof
BeitragVerfasst: Mi 04.06.08 19:09 
Auszug aus der Delphi 2007 Hilfe:

Zitat:
Um ein Attribut zu testen, führen Sie eine AND-Verknüpfung des Attr-Feldes mit der Attributkonstante durch. Besitzt die Datei das betreffende Attribut, ist der zurückgegebene Wert größer als 0. Wurde beispielsweise eine verborgene Datei gesucht, ergibt der folgende Ausdruck true:

(SearchRec.Attr and faHidden) <> 0.


Schmeiß also dein Case weg, und teste einzeln mit if.
Hendi48 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 271



BeitragVerfasst: Mi 04.06.08 19:42 
Him
aber wie kann ich dann prüfen, ob der SearchRec ein Ordner ist, der archiviert werden kann?
ausblenden Delphi-Quelltext
1:
if (SR.Attr and faDirectory and faArchive) <> 0 then					

Das geht nicht.

Gruß,
Hendi
nagel
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 708

Win7, Ubuntu 10.10

BeitragVerfasst: Mi 04.06.08 19:48 
Vermutlich: (SR.Attr and faDirectory <> 0And (SR.Attr and faArchive <> 0)
Hendi48 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 271



BeitragVerfasst: Mi 04.06.08 20:14 
Oh,
ich habe einen Denkfehler gemacht. Ich muss ja gar nicht mehr prüfen ob ein Ordner archiviert ist, ich kann ja einfach das machen um zu unterscheiden ob es eine Datei / ein Ordner ist.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
    if (SR.Attr and faDirectory <> 0then
      sAttr := 'Ordner'
    else
      sAttr := 'Datei';


Trotzdem, Danke für die Hilfe!

Gruß,
Hendi