Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi AdvBuildFileList findet keine Systemdateien? (https://www.delphipraxis.net/134641-advbuildfilelist-findet-keine-systemdateien.html)

HeikoAdams 26. Mai 2009 09:11


AdvBuildFileList findet keine Systemdateien?
 
Hallo,
ich versuche, den Inhalt des Ordners C:\Dokumente und Einstellungen\ich\Anwendungsdaten\Microsoft\Crypto mit Delphi zu sichern.
Um den Inhalt des Verzeichnisses zu bekommen, verwende ich
Delphi-Quellcode:
    if AdvBuildFileList(IncludeTrailingPathDelimiter(aDir) + '*.*',
      $00017FFF, aFileList, amSuperSetOf,
      [flFullNames, flRecursive]) then
    begin
      for nCount := aFileList.Count - 1 downto 0 do
        if Like(aFileList.Strings[nCount], '*\.')
          or Like(aFileList.Strings[nCount], '*\..') then
          aFileList.Delete(nCount);
    end;

    aFileList.Sort;
Jedoch liefert mir diese Routine nur den Unterordner RSA ohne die Dateien darin. :wiejetzt: Mache ich da was falsch oder schlägt da nen Bug in AdvBuildFileList zu?

rhodan 26. Mai 2009 13:04

Re: AdvBuildFileList findet keine Systemdateien?
 
moin...

hab ich grad mal über die suche hier im forum gefunden:

http://www.delphipraxis.net/internal...vbuildfilelist


hoffe das hilft etwas weiter..

ich gehe mal davon aus das die systemdateien ebenfalls verschlüsselt sind und sie aus diesem grund nicht angezeigt werden.

LG aus hamburg,

rob

HeikoAdams 26. Mai 2009 14:51

Re: AdvBuildFileList findet keine Systemdateien?
 
Ich hab die Lösung gefunden. Die Funktion AdvBuildFileList ist buggy, da sie keine versteckten Verzeichnisse findet.
Hier meine gepatchte Version:
Delphi-Quellcode:
function AdvBuildFileList(const Path: string; const Attr: Integer; const Files: TStrings;
  const AttributeMatch: TJclAttributeMatch; const Options: TFileListOptions;
  const SubfoldersMask: string; const FileMatchFunc: TFileMatchFunc): Boolean;
var
  FileMask: string;
  RootDir: string;
  Folders: TStringList;
  CurrentItem: Integer;
  Counter: Integer;
  FindAttr: Integer;

  procedure BuildFolderList;
  var
    FindInfo: TSearchRec;
    Rslt: Integer;
    sErr: string;
  begin
    Counter := Folders.Count - 1;
    CurrentItem := 0;

    while CurrentItem <= Counter do
    begin
      // searching for subfolders

      //HA 090526 Modified to find hidden directories also ..
      //Rslt := FindFirst(Folders[CurrentItem] + '*.*', faDirectory, FindInfo);
      Rslt := FindFirst(Folders[CurrentItem] + '*.*', faAnyFile, FindInfo);
      //..

      try
        while Rslt = 0 do
        begin
          if (FindInfo.Name <> '.') and (FindInfo.Name <> '..') and
            (FindInfo.Attr and faDirectory = faDirectory) then
            Folders.Add(Folders[CurrentItem] + FindInfo.Name + DirDelimiter);

          Rslt := FindNext(FindInfo);
        end;
      finally
        FindClose(FindInfo);
      end;
      Counter := Folders.Count - 1;
      Inc(CurrentItem);
    end;
  end;

  procedure FillFileList(CurrentCounter: Integer);
  var
    FindInfo: TSearchRec;
    Rslt: Integer;
    CurrentFolder: string;
    Matches: Boolean;
  begin
    CurrentFolder := Folders[CurrentCounter];

    Rslt := FindFirst(CurrentFolder + FileMask, FindAttr, FindInfo);

    try
      while Rslt = 0 do
      begin
         Matches := False;

         case AttributeMatch of
           amAny:
             Matches := True;
           amExact:
             Matches := Attr = FindInfo.Attr;
           amSubSetOf:
             Matches := (Attr and FindInfo.Attr) = Attr;
           amSuperSetOf:
             Matches := (Attr and FindInfo.Attr) = FindInfo.Attr;
           amCustom:
             if Assigned(FileMatchFunc) then
               Matches := FileMatchFunc(Attr, FindInfo);
         end;

         if Matches then
           if flFullNames in Options then
             Files.Add(CurrentFolder + FindInfo.Name)
           else
             Files.Add(FindInfo.Name);

        Rslt := FindNext(FindInfo);
      end;
    finally
      FindClose(FindInfo);
    end;
  end;

begin
  Assert(Assigned(Files));
  FileMask := ExtractFileName(Path);
  RootDir := ExtractFilePath(Path);

  Folders := TStringList.Create;
  Files.BeginUpdate;
  try
    Folders.Add(RootDir);

    case AttributeMatch of
      amExact, amSuperSetOf:
        FindAttr := Attr;
    else
      FindAttr := faAnyFile;
    end;

    // here's the recursive search for nested folders

    if flRecursive in Options then
      BuildFolderList;

    for Counter := 0 to Folders.Count - 1 do
    begin
      if (((flMaskedSubfolders in Options) and (StrMatches(SubfoldersMask,
        Folders[Counter], 1))) or (not (flMaskedSubfolders in Options))) then
          FillFileList(Counter);
    end;
  finally
    Folders.Free;
    Files.EndUpdate;
  end;
  Result := True;
end;


Alle Zeitangaben in WEZ +1. Es ist jetzt 19:39 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz