Please enable JavaScript to view this site.

KOL/MCK - User Guide

List of Files and Directories - TDirList

 

Since I started talking about lists, it is natural to continue with a special kind of list - a list of file names. KOL has an object type TDirList, which greatly simplifies the work with directories. It encapsulates a call to API functions that view the contents of a folder and constitutes its directory. All you need to start working with files in the entire directory is to call one of the constructors (NewDirList or NewDirListEx), and get an object that stores the "dossier" for all ordered files located in the specified path (and meeting the stated requirements).

 

So, "constructors":

 

NewDirList(path, filter, attr)- creates a list of directories, reading files and / or directories (this depends on the parameter that sets the attributes of the searched file-director objects, for example, FILE_ATTRIBUTE_DIRECTORY will read only subdirectories, FILE_ATTRIBUTE_ARCHIVE - only files, and 0 - all names indiscriminately). The filter can only be a single filter, but it accepts the wildcard characters '*' and '?'.

NewDirListEx(path, filters, attr) - differs from the previous constructor in that it allows you to use several patterns, separated by the ';' character, and patterns prefixed with '^' are considered anti-filters - to exclude names that match such patterns.

 

 

The created object of type TDirList has the following methods and properties:

 

Path - a string that stores the path to the directory (always terminated by the '\' character, that is, you can always concatenate DL.Path + DL.Names [i] to get the full path to the i-th file);

Count - returns the number of file names and subdirectories in the list;

Names[i] - returns file names by their index;

IsDirectory[i] - checks that the object with index i is a directory;

Items[i] - complete structure with information about the file / directory (it contains all the information provided by the system, including the file size, date of its creation / modification / last access, short name, attributes);

Clear - clears the list;

ScanDirectory(path, filter, attr) - allows you to scan the contents of another (or rescan the contents of the same) directory, similar to the NewDirList constructor;

ScanDirectoryEx(path, filters, attr) - similar to the previous method, but according to advanced rules, similar to the NewDirListEx constructor;

Sort(rules) - sorts names according to the specified rules. A whole array of rules is specified, which are applied sequentially during comparison until the first rules detect differences between names. For example, the rule sdrFoldersFirst does not distinguish between files and files, and between directories and directories, but distinguishes only directories from files. Some rules are used as modifiers to apply other rules, for example sdrCaseSensitive;

FileList(separator, dirs, fullpaths) - returns a list of files as a string, in which the files are separated by the specified separator;

OnItem - an event that is triggered for each read item when scanning a directory, and allows you to make a decision about including or not including a name in the list in accordance with the algorithm specified in the event handler. Of course, in order for the handler for this event to be assigned before scanning the directory, when calling the constructor, pass an empty string as a path, then assign your handler to the object, and only then call the scanning method ScanDirectory or ScanDirectoryEx.

 

Although the object described here does not allow scanning the contents of a directory for all subdirectories, nevertheless, organizing a recursive traversal of the entire folder tree is a completely solvable task even for a beginner. An example of such a recursive traversal can be found in the KOL.pas module itself, in the implementation of the DirectorySize function, which just uses the TDirList object to scan the contents of directories.

 

KOL / MCK User Guide - Created by Carl Peeraer - Diamant Soft, based on the work of Vladimir Kladov - Artwerp.be

  

Keyboard Navigation

F7 for caret browsing
Hold ALT and press letter

This Info: ALT+q
Nav Header: ALT+n
Page Header: ALT+h
Topic Header: ALT+t
Topic Body: ALT+b
Exit Menu/Up: ESC