type TSortDirRules =( sdrNone, sdrFoldersFirst, sdrCaseSensitive, sdrByName, sdrByExt, sdrBySize, sdrBySizeDescending, sdrByDateCreate, sdrByDateChanged, sdrByDateAccessed, sdrInvertOrder );
List of rules (options) to sort directories. Rules are passed to Sort method in an array, and first placed rules are applied first.
function NewDirList( const DirPath, Filter: KOLString; Attr: DWORD ): PDirList;
Creates directory list object using easy one-string filter. If Attr = FILE_ATTRIBUTE_NORMAL, only files are scanned without directories. If Attr = 0, both files and directories are listed.
function NewDirListEx( const DirPath, Filters: KOLString; Attr: DWORD ): PDirList;
Creates directory list object using several filters, separated by ';'. Filters starting from '^' consider to be anti-filters, i.e. files, satisfying to those masks, are skept during scanning.
var DefSortDirRules: array[ 0 . . 3 ] of TSortDirRules =( sdrFoldersFirst, sdrByName, sdrBySize, sdrByDateCreate );
Default rules to sort directory entries.
function DirectorySize( const Path: KOLString ): I64;
Returns directory size in bytes as large 64 bit integer.
TDirList
TDirList( unit KOL.pas ) TObj _TObj
TDirList = object( TObj )
Allows easy directory scanning. This is not visual object, but storage to simplify working with directory content.
TDirList properties
property Items[ Idx: Integer ]: PFindfileData; default;
Full access to scanned items (files and subdirectories).
property IsDirectory[ Idx: Integer ]: Boolean;
Returns TRUE, if specified item represents a directory, not a file.
property Count: Integer;
Number of items.
property Names[ Idx: Integer ]: KOLString;
Full long names of directory items.
property Path: KOLString;
Path of scanned directory.
TDirList methods
Destructor. As usual, call Free method to destroy an object.
procedure Clear;
Call it to clear list of files.
procedure ScanDirectory( const DirPath, Filter: KOLString; Attr: DWord );
Call it to rescan directory or to scan another directory content (method Clear is called first). Pass path to directory, file filter and attributes to scan directory immediately.
Note: Pass FILE_ATTRIBUTE_... constants or-combination as Attr parameter. If 0 passed, both files and directories are listed.
procedure ScanDirectoryEx( const DirPath, Filters: KOLString; Attr: DWord );
Call it to rescan directory or to scan another directory content (method Clear is called first). Pass path to directory, file filter and attributes to scan directory immediately.
Note: Pass FILE_ATTRIBUTE_... constants or-combination as Attr parameter.
procedure Sort( Rules: array of TSortDirRules );
Sorts directory entries. If empty rules array passed, default rules array DefSortDirRules is used.
function FileList( const Separator: KOLString; Dirs, FullPaths: Boolean ): KOLString;
Returns a string containing all names separated with Separator. If Dirs=FALSE, only files are returned.
procedure DeleteItem( Idx: Integer );
Allows to delete an item from the directory list (not from the disk!)
procedure AddItem( FindData: PFindFileData );
Allows to add arbitrary item to the list.
procedure InsertItem( idx: Integer; FindData: PFindFileData );
Allows to add arbitrary item to the list.
TDirList events
property OnItem: TOnDirItem;
This event is called on reading each item while scanning directory. To use it, first create PDirList object with empty path to scan, then assign OnItem event and call ScanDirectory with correct path.