Results 1 to 12 of 12

Thread: NLDRcsFileUtils

  1. #1

    NLDRcsFileUtils

    ------------
    De sources van NLDDanyUtils zijn te vinden in:
    ftp://ftp.nldelphi.com/public/OpenSo.../NLDDanyUtils/
    ------------

    Biedt een aantal features aan:

    1. Genereren van een file list (van files van een bepaalde naam en bepaalde attributen). De lijst bevat zgn 'TSearchRec' records die alle gegevens van de files bevatten. Dit is geïmplementeerd in de class "TFileList".

    2. Genereren van een file list in een 'TStrings' object (van files van een bepaalde naam en bepaalde attributen) met enkel de naam van de files, met of zonder extentie. Dit feature aanvaardt 1 (in een String) of meerdere te zoeken filenamen (in een TStringList).

    3. Zoeken naar het bestaan van een file (met een bepaalde naam - met wildcards - en bepaalde attributen). De naam van de gevonden file (indien gevonden) wordt teruggegeven.

    Alle bovenstaande features kunnen (desgewenst) ook recursief in subdirectories kijken/zoeken. Bovendien kunnen de gevonden filenamen ook (desgewenst) het path van de file bevatten (en niet alleen de naam); dat path kan relatief (tegenover de directory waarin de procedure aangeroepen wordt) of absoluut ('C:\aaa\bbb\...') zijn.

    4. Zoeken naar het bestaan van een directory (met een bepaalde naam - met wildcards - en bepaalde attributen). De naam van de gevonden directory (indien gevonden) wordt teruggegeven.

    5. Het terugvertalen van een "ShortPath" naar een "LongPath".

    De interface:
    Code:
    interface
    
    uses SysUtils,
      Classes;
    
    const
      (* Kind of file *)
      faFile = $80;                                   {NOT VolumeID, NOT Directory}
      //faVolumeID  = $08;	Volume ID files
      //faDirectory	= $10;	Directory files
      //faAnyFile   = $7F;  Any File
      faAnyKind = faFile or faDirectory or faVolumeId;
    
      (* Status of file *)
      faNormal = $40;                                 {NOT ReadOnly, NOT Hidden, NOT SysFile}
      //faReadOnly  = $01;	Read-only files
      //faHidden    = $02;	Hidden files
      //faSysFile   = $04;	System files
      //faArchive	= $20;	Archive files
      faAnyStatus = faNormal or faReadOnly or faArchive or faHidden or faSysFile;
    
      (* "NormalFile" definition *)
      faNormalFile = faFile or faNormal;
    
      (* Bitsdefinition *)
      faFileKindBits = faFile or faDirectory or faVolumeId;
      faFileStatusBits = faNormal or faReadOnly or faArchive or faHidden or faSysFile;
    
    type
      TAttributeCheck = (acStrict, acRelaxed);
      TIncludePath = (ipNone, ipRelative, ipFull);
      //TFileListMode = (mdMask, MdRegExp);
    
      TFileList =
        class(TList)
      private
        //TMode: TFileListMode;
        procedure DisposeFileList;
      public
    
        constructor Create;
        destructor Destroy; override;
    
        procedure MakeFileList(
          Fn: string;                                 // filename to find (rootdir is derived from it)
          Attr: Integer;                              //file attributes to find
          Check: TAttributeCheck;                     // strict or relaxed attribute check
          SubDirs: Boolean = false;                   // search in subdirs too
          IncludePath: TIncludePath = ipNone;         // include full path in the filenames found
          MaxNumber: Integer = MaxInt); overload;     // maximum number of entries in the list fo names found
    
        procedure MakeFileList(
          RootDir: string;                            // start directory
          Fn: string;                                 // filename to find
          Attr: Integer;                              // file attributes to find
          Check: TAttributeCheck;                     // strict or relaxed attribute check
          SubDirs: Boolean = false;                   // search in subdirs too
          IncludePath: TIncludePath = ipNone;         // include full path in the filenames found
          MaxNumber: Integer = MaxInt); overload;     // maximum number of entries in the list fo names found
    
        procedure MakeFileList(
          RootDir: string;                            // start directory
          FNames,                                     // list of filenames to find
          Excluded: Tstrings;                         // list of filenames to exclude
          Attr: Integer;                              // file attributes to find
          Check: TAttributeCheck;                     // strict or relaxed attribute check
          SubDirs: Boolean = false;                   // search in subdirs too
          IncludePath: TIncludePath = ipNone;         // include full path in the filenames found
          MaxNumber: Integer = MaxInt); overload;     // maximum number of entries in the list fo names found
    
        procedure AddToFileList(const Rec: TSearchrec);
        procedure GetEntry(const Index: Integer; var Rec: TSearchrec);
        procedure SortFileList;
    
        //property Mode: TFileListMode read TMode write TMode;
      end;
    
      {
      TFileList.MakeFileList:
       This procedure builds a list of 'TSearchRec' members, with attributes defined in the
       parameters. The "Attr" part of the TSearchRec members is extended with the extra
       attributes "faFile" and "faNormal".
    
       TFileList.MakeFileList parameters:
       - 'RootDir'     : The (top/root)directory the action starts in
                         if it is empty, an attempt is made to extract it from 'Fn',
                         if that fails then the current directory is used as RootDir
                         In functions/procedures where the parameter "RootDir" is not
                         present an attempt is made to derived from "Fn".
       - 'Fn'      (1) : The filename to be found, can contain wildcards
       - 'FNames'  (2) : a list of filenames to be found, can contain wildcards
       - 'Excluded'(2) : a list of filesnames (or directorynames) to exclude from the list
       - 'Attr'        : The file-attributes to be found
       - 'Check'       : Relaxed or strict checking of the file attributes (see the function 'Match')
       - 'SubDirs'     : True = also go into subdirs
       - 'IncludePath' : The path included in the filenames (see type 'TIncludepath')
       - 'MaxNumber'   : The maximum number of entries allowed in the list (default MaxInt)
    
          (1) and (2) are mutual exclusive
      }
    
    { FileNameExists
    This function checks if file 'Fn' with attributes 'Attr' exists and returns its name.
    If it does not exist, it returns ''.
    All parameters have the same meaning as in 'TFileList.MakeFileList' (see above)
    }
    function FileNameExists(
      Fn: string;                                     // filename to check
      Attr: Integer;                                  // file attributes to find
      Check: TAttributeCheck;                         // strict or relaxed attribute check
      SubDirs: Boolean = false;                       // search in subdirs too
      IncludePath: TIncludePath = ipNone              // include full path in the filenames found
      ): string;
    
    
    { GetFileNames
    This procedure gets filenames in a TStrings object (like a TMemo.Lines).
    The directory to start in is extracted from "Fn". If that fails then the
    current directory is used as RootDir.
    If 'RemoveExtension' is set to 'True', the extensions are removed from the filenames
    All other parameters have the same meaning as in 'TFileList.MakeFileList' (see above)
    }
    procedure GetFileNames(
      Fn: string;                                     // filename to find (the rootdir is derived from it)
      Attr: Integer;                                  // file attributes to find
      Check: TAttributeCheck;                         // strict or relaxed attribute check
      RemoveExtension: Boolean;                       // the extention of the filenames found is to be removed in the list
      List: TStrings;                                 // the search results (found filenames)
      Subdirs: Boolean = false;                       // search in subdirs too
      IncludePath: TIncludePath = ipNone;             // include full path in the filenames found
      MaxNumber: Integer = MaxInt                     // maximum number of entries in the list fo names found
      ); overload;
    
    
    { GetFileNames
    This procedure gets filenames in a TStrings object (like a TMemo.Lines).
    The filename search action starts in "RootDir". If Rootdir is empty then an attempt
    is made to extract RootDir from "Fn". If that fails then the
    current directory is used as RootDir.
    If 'RemoveExtension' is set to 'True', the extensions are removed from the filenames
    All other parameters have the same meaning as in 'TFileList.MakeFileList' (see above)
    }
    procedure GetFileNames(
      RootDir: string;                                // start directory
      Fn: string;                                     // filename to find
      Attr: Integer;                                  // file attributes to find
      Check: TAttributeCheck;                         // strict or relaxed attribute check
      RemoveExtension: Boolean;                       // the extention of the filenames found is to be removed in the List
      List: TStrings;                                 // the search results (found filenames)
      Subdirs: Boolean = false;                       // search in subdirs too
      IncludePath: TIncludePath = ipNone;             // include full path in the filenames found
      MaxNumber: Integer = MaxInt                     // maximum number of entries in the list fo names found
      ); overload;
    
    
    { GetFileNames
    This procedure is identical to the above one, but one can give more paths to search
    for in de TStrings variable 'FNames'.
    Here if Rootdir is empty then the current directory is used as RootDir.
    Additionally the files in "Excluded" are not in the filename list.
    }
    procedure GetFileNames(
      RootDir: string;                                // start directory
      FNames,                                         // list of filenames to find
      Excluded: Tstrings;                             // list of filenames to exclude
      Attr: Integer;                                  // file attributes to find
      Check: TAttributeCheck;                         // strict or relaxed attribute check
      RemoveExtension: Boolean;                       // the extention of the filenames found is to be removed in the List
      List: TStrings;                                 // the search results (found filenames)
      Subdirs: Boolean = false;                       // search in subdirs too
      IncludePath: TIncludePath = ipNone;             // include full path in the filenames found
      MaxNumber: Integer = MaxInt                     // maximum number of entries in the list fo names found
      ); overload;
    
    
    { DirectoryNameExists
    This function checks if "DirName" exists ("DirName" can contain wildcards in any
    part of it) and returns its (with resolved wildcards) name (with or without trailing backslash).
    If the directory "DirName" does not exist, the function returns an empty string.
    }
    function DirectoryNameExists(DirName: string; const IncludeBackSlash: Boolean =
      true): string;
    
    
    { ExpandToLongPathName
    This functions returns the "long" pathname of "ShortPath", with or without trailing backslash.
    See "ExtractShortPathName" (in SysUtils) for the opposite function.
    }
    function ExpandToLongPathName(ShortPath: string; const IncludeBackSlash: Boolean
      = true): string;
    Last edited by Dany; 05-Aug-07 at 22:42.

  2. #2
    Hoi, er is een nieuwe versie:

    De class "TFileList" is nu een descendant van de class "TList". Moest dringend eens gebeuren, de implementatie was nog van v????r de "TList" tijd...

    Verder is de functionaliteit van de unit, noch zijn interface, gewijzigd.
    Veel plezier.
    Last edited by Dany; 10-Jun-04 at 20:17.
    Vriendelijke groeten,
    Dany

  3. #3
    Hoi, weer een aanpassing:

    De file "attributes" gebruikt in de routines zijn nu gesplitst in een "Kind" (soort file vb "directory") en een "Status" (toestand file vb "read only"). Verder zijn de attribute waarden "faFile" en "faNormalFile" gedefinieerd.
    Een en ander laat een logischer gebruik van de fileattributes toe.
    Last edited by Dany; 15-Jul-07 at 11:53.
    Vriendelijke groeten,
    Dany

  4. #4
    Hoi,

    Weer een nieuwe versie:

    Een aantal aanpassingen voor de duidelijkheid, de snelheid en het gebruiksgemak. Zie in de unit zelf voor de beschrijving ervan.
    Opgepast: in TFileList is "NumberOfEntries" vervangen door "Count". Verder is alles hetzelfde gebleven: de indexrange loopt van 1 tot Count (niet van 0 tot Count - 1).
    Last edited by Dany; 15-Jul-07 at 11:53.
    Vriendelijke groeten,
    Dany

  5. #5
    Hoi,

    Weer een verbetering:

    V????r de aanroep van "MakeFileList", "GetFileNames" of "FileNameExists" is een
    explicite "ChDir" niet meer nodig, de "root" directory (waarin het zoeken naar files start) kan nu ook meegegeven worden met de te zoeken filenaam (parameter "Fn").

    Dus:
    Code:
    MakeFileList ('xxx\*.pas', ...   // nieuwe manier
                                     // is exact hetzelfde als:
    ChDir('xxx');                    // oude manier
    MakeFileList('*.pas', ...
    De "oude" manier werkt trouwens ook nog..
    Last edited by Dany; 21-Jul-04 at 18:34.
    Vriendelijke groeten,
    Dany

  6. #6
    Hoi,

    Vandaag functie toegevoegd:
    Code:
    function DirectoryNameExists(DirName: string; const IncludeBackSlash: boolean = true ): string;
    Deze functie checkt voor het bestaan van "DirName" na het oplossen van de "wildcards" ('*' en '?') in die "DirName". Als de directory "DirName" bestaat dan geeft de functie de (echte) naam van die directory terug (al dan niet met de "trailingbackslash"), ingeval de directory "DirName" niet bestaat wordt een lege string teruggegeven.

    Alle andere procedures en functies in deze unit gebruiken nu bovenstaande functie om wildcards in een (root) directory op te lossen: voortaan kunnen dus wildcards in alle directorypaths meegegeven worden.

    Veel plezier.
    Last edited by Dany; 22-Jul-04 at 11:54.
    Vriendelijke groeten,
    Dany

  7. #7
    Hoi,

    Weer een functie toegevoegd:

    "ExpandToLongPathName", het tegenovergestelde van "ExtractShortPathName".
    Code:
    function ExpandToLongPathName(ShortPath: string; const IncludeBackSlash: Boolean = true): string;
    Veel plezier.
    Last edited by Dany; 25-Jul-04 at 13:20.
    Vriendelijke groeten,
    Dany

  8. #8
    Er is een nieuwe versie van de "Examples" html file, die was hard aan aanpassing toe...
    Last edited by Dany; 31-Jul-04 at 09:53.

  9. #9
    Er is nu een overloaded versie van "MakeFileList":

    Code:
    procedure MakeFileList(FNames, Excluded: Tstrings;
          Attr: Integer;
          Check: TAttributeCheck;
          SubDirs: Boolean = false;
          IncludePath: TIncludePath = ipNone;
          MaxNumber: Integer = MaxInt); overload;
    De parameter "FNames" bevat een lijst van files die moeten gezocht worden, de parameter "Excluded" bevat een lijst van files (of directories) die moeten genegeerd worden tijdens het opmaken van de filelijst.

    Hetzelfde type overload is er ook voor "GetFileNames".

    Veel plezier...

  10. #10
    Kleine aanpassing: de constanten "faAnyKind" en "faAnyStatus" toegevoegd.

  11. #11
    Toegevoegd aan de meeste procedures/functies: een "RootDir" parameter, die je zelf laat bepalen in welke directory de zoek aktie start (vroeger werd die altijd uit de "Fn" parameter --de te zoeken path/naam-- gehaald). Soms is dit makkelijker in gebruik. De vorige versie (zonder "Rootdir" bestaat ook nog --overloaded--).

  12. #12
    Vriendelijke groeten,
    Dany

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •