Einzelnen Beitrag anzeigen

Astat

Registriert seit: 2. Dez 2009
Ort: München
320 Beiträge
 
Lazarus
 
#7

Re: probleme mit FindallFiles...

  Alt 5. Feb 2010, 20:08
Zitat von seppi.tm:
..so, das geht alles eig. wunderbar doch wenn ich auf einen ordner innerhalb von C:\Dokumente und Einstellungen oder auf einer anderen Partition zugreifen will gibt mir die funktion nichts zurück... wieso?
Hallo seppi.tm, kannst ja mal mit unten stehender procedure vergleichen, funkt bei mir problemlos.


Delphi-Quellcode:

type
  TWin32FindDataCallback = procedure(const AFile: string); stdcall;

procedure FindFiles(const Dir: String; lpfnCallBack: TWin32FindDataCallback);
var
  hFind: THandle;
  wfd: TWin32FindData;
  sFileName: String;

  function IsDirectory(const Name: String): Boolean;
  var
    Atr: DWORD;
  begin
    Atr := GetFileAttributes(PChar(Name));
    Result := (Atr <> $FFFFFFFF) and (Atr and $010 <> 0) and (Atr and $400 = 0);
  end;

  function AddBackslash(const s: String): String;
  begin
    if (s <> '') and (s[Length(s)] <> '\') then
      Result := s + '\else Result := s;
  end;

begin
  if (Dir <> '') and (Pos(#0, Dir) = 0) and IsDirectory(Dir) then begin
    hFind := FindFirstFile(PChar(AddBackslash(Dir) + '*'), wfd);
    if hFind <> DWORD(-1) then begin
      repeat
        if (StrComp(wfd.cFileName, '.') <> 0) and
          (StrComp(wfd.cFileName, '..') <> 0) then
        begin
          sFileName := AddBackslash(Dir) + wfd.cFileName;
          if wfd.dwFileAttributes and $10 = 0 then lpfnCallBack(sFileName) else
            FindFiles(sFileName, lpfnCallBack);
        end;
      until not FindNextFile(hFind, wfd);
      Windows.FindClose(hFind);
    end;
  end;
end;

procedure Win32FindDataCallback(const AFile: string); stdcall;
begin
  Form1.Memo1.Lines.Add(AFile)
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  FindFiles('C:\Dokumente und Einstellungen', Win32FindDataCallback);
end;
lg. Astat
Lanthan Astat
06810110811210410503210511511603209711003210010110 9032084097103
03211611111604403209711003210010110903210010510103 2108101116122
11610103209010110510810103206711110010103210511003 2068101108112
10410503210310111509910411410510109810111003211910 5114100046
  Mit Zitat antworten Zitat