------------
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;
Bookmarks