Searches for and returns information about an item in the filesystem, performs a directory search.
If
item_spec contains an absolute path, then the first procedure searches the filesystem for an item that matches the name
item_spec and whose attributes are all contained in
attrib_mask. Otherwise, it searches relative to the current directory (see
CurDir). In any case, if a matching item is not found,
out_attrib is assigned to zero and an empty string is returned. Otherwise,
out_attrib is assigned with the attribute flags of the item, and the name of the item, without a path, is returned.
item_spec may include an asterisk (
*, for matching any adjacent characters) or one or more question marks (
?, for matching any individual character). If it does, the procedure searches for the first such item. If found, subsequent calls with
item_spec equal to an empty string will return the next item matching the name
item_spec until no more such items are found. If
attrib_mask is omitted from these subsequent calls, the procedure searches for items with the same attributes as in the previous call.
The second procedure behaves the same as
Dir( item_spec, attrib_mask, *p_out_attrib ).
The third procedure behaves the same as
Dir( "", , out_attrib ).
The fourth procedure behaves the same as
Dir( "", , *p_out_attrib ).
File Attributes:
Files and directories and other items can be said to possess so-called file attributes; metadata that describes the item. The meaning of this metadata varies with operating system and the file system it uses. The following macros are used as bit-flags with
attrib_mask,
out_attrib and
*p_out_attrib. Their values can be combined to form a mask using
Operator Or, or individual values can be checked using
Operator And. To access them,
Include "dir.bi".
# define fbReadOnly &h01
The item cannot be written to or deleted.
DOS & Windows: The item has the "read-only" attribute set.
Linux:The item has no write permissions associated with the current user or group, nor is it globally writable. (Whether or not the user has root permissions is ignored.)
# define fbHidden &h02
The item is hidden in ordinary directory listings.
DOS & Windows: The item has the "hidden" attribute set.
Linux: The item's name has a period (.) as the first character.
# define fbSystem &h04
The item is used almost exclusively by the system.
DOS & Windows: The item has the "system" attribute set.
Linux: The item is either a character device, block device, named pipe (FIFO) or Unix socket.
# define fbDirectory &h10
The item is a directory. Includes the current (.) and parent (..) directories as well.
DOS & Windows & Linux: The item is a directory.
# define fbArchive &h20
The item may be backed up after some automated operations.
DOS & Windows: The item has the "archive" attribute set (automatically set after every write access to a file).
Linux: The item is not a directory; typical filesystems do not support this metadata.
# define fbNormal (fbReadOnly or fbArchive)
The item is a file or directory.
Items found having no attributes are always matched, regardless of the value of
attrib_mask. An item will not be matched if it has one or more attributes that aren't specified in
attrib_mask.
If
attrib_mask does not include
fbArchive, then
Dir may widen the check to include
fbDirectory, but it is recommended to add
fbDirectory explicitly, if that is the behaviour sought. Finer control can be gained by checking the
out_attrib value for the desired set of attributes.