Autor Beitrag
bbfan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 164



BeitragVerfasst: Mo 04.04.05 10:27 
Hallo!

Ich benutzte die alte rekursive Methode, um Verzeichnisse nach Dateien zu durchsuchen.
Also mit findFirst.... Ich benutze bewusst faAnyfile, damit auch versteckte Verzeichnisse erfasst werden.
Allerdings ist mir aufgefallen, dass faAnyFile keine System Verzeichnisse findet, wie z.B.:
C:\Documents and Settings\Administrator\Local Settings
Der Order "Local Settings" wird nicht gefunden.

Wie schaffe ich es, dass auch solche Verzeichnisse gefunden werden?

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
 found := FindFirst(Pfad + '*', faAnyFile, sr);
   while found = 0 do
    begin
    if (sr.Name[1] <> '.') AND (IsDirectory(pfad+sr.Name)) then
.......


IsDirc - Function

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
function IsDirectory(const Dir: string): Boolean;
var
  R: DWORD;
begin
  Result := false;
  R := GetFileAttributes(PChar(Dir));
  if (R = FILE_ATTRIBUTE_DIRECTORY) or (r = 48) or (r = 20) or (r = 16) then Result := true;
end;


Moderiert von user profile iconAXMD: Code- durch Delphi-Tags ersetzt.
opfer.der.genauigkeit
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 754
Erhaltene Danke: 1



BeitragVerfasst: Mo 04.04.05 11:22 
Hallo,

Du suchst nur nach Dateien.

ausblenden Delphi-Quelltext
1:
  FindFirst(Pfad + '*', faAnyFile+faDirectory, sr);					

_________________
Stellen Sie sich bitte Zirkusmusik vor.
bbfan Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 164



BeitragVerfasst: Mo 04.04.05 12:38 
Das stimmt leider nicht so ganz. faAnyFile erfasst einfach alles, auch Directorys.
Wenn man nur mit faDirectory arbeitet, werden verscheckte Verzeichnisse nicht erfasst.
Deswegen erfasse ich mit faAnyfile alles und checke mit meiner isDirectory Routine ob ein Verzeichnis ist.

Überings mit
ausblenden Delphi-Quelltext
1:
found := FindFirst(Pfad + '*', faAnyFile + faDirectory, sr);					


findet er gar kein Verzeichnis.

Moderiert von user profile iconAXMD: Code- durch Delphi-Tags ersetzt.
AXMD
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 4006
Erhaltene Danke: 7

Windows 10 64 bit
C# (Visual Studio 2019 Express)
BeitragVerfasst: Mo 04.04.05 12:42 
Warum so kompliziert :shock:

ausblenden Delphi-Quelltext
1:
if (sr.Attributes and faDirectory) = faDirectory then {...Verzeichnis}					


AXMD
opfer.der.genauigkeit
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 754
Erhaltene Danke: 1



BeitragVerfasst: Mo 04.04.05 12:44 
:lol: Hast recht, da dürft er garnix finden.

Bist du Admin auf dem System?

_________________
Stellen Sie sich bitte Zirkusmusik vor.
MathiasSimmack
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Mo 04.04.05 12:47 
Ich denke schon, @opfer:
user profile iconbbfan hat folgendes geschrieben:
C:\Documents and Settings\Administrator\Local Settings
Der Order "Local Settings" wird nicht gefunden.

denn sonst würde er vermutlich gar nicht erst in den Ordner reinkommen. Andererseits ist das aber trotzdem eine gute Frage, denn einige Ordner (auch im Windows-Verzeichnis) sind ohne passende Rechte nicht ermittelbar.
bbfan Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 164



BeitragVerfasst: Mo 04.04.05 12:54 
also rechte auf das Verzeichnis habe ich schon. Bin lokaler Admin.
Meine Routine funktioniert auch einwandfrei, nur dass eben bestimmte Verzeichnisse, wie "Local Settings" nicht erfasst werden.

Das hier

if (sr.Attributes and faDirectory) = faDirectory then

würde vielleicht bei der Erkennung helfen, aber wie gesagt.... wie soll etwas erkannt werden, wenn es nicht im SR Record drinne steht?

Moderiert von user profile iconAXMD: Delphi-Tags hinzugefügt.
bbfan Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 164



BeitragVerfasst: Mo 04.04.05 13:02 
ok. hab dank euch die Lösung gefunden.

Also Schritt 1: suche mit faAnyFile
Schritt 2: Überprüfung mit

ausblenden Delphi-Quelltext
1:
 if (sr.Name[1] <> '.') AND ((sr.Attr and faDirectory) = faDirectory) then					



Vielen DANK , Jungs!

Moderiert von user profile iconAXMD: Delphi-Tags hinzugefügt.
AXMD
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 4006
Erhaltene Danke: 7

Windows 10 64 bit
C# (Visual Studio 2019 Express)
BeitragVerfasst: Mo 04.04.05 13:18 
@bbfan: Bitte das nächste Mal Delphitags verwenden. Wie das geht steht in der Hilfe.

AXMD
bbfan Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 164



BeitragVerfasst: Mo 04.04.05 13:21 
geht klar! :D