[Overview][Constants][Types][Procedures and functions][Variables][Index] Reference for unit 'LazFileUtils' (#lazutils)

ForceDirectoriesUTF8

Creates the directories specified in Dir if they do not already exist.

Declaration

Source position: lazfileutils.pas line 128

function ForceDirectoriesUTF8(

  const Dir: string

):Boolean;

Arguments

Dir

  

Device and path information to examine the function.

Function result

True when directories exist or are successfully created in the function.

Description

ForceDirectoriesUTF8 is a Boolean function which creates any missing directories specified in the UTF-8-encoded Dir argument. Dir can contain notation using the following conventions:

Windows device and path
A disk drive available on the local system, such as 'C:' or 'D:', and directory names. For example: 'C:\Windows\Fonts'.
Universal Naming Convention identifier
UNC notation like '\\server\share\path\to\dir' (for Windows) or '//hostname/path/to/dir' (for UNIX-like systems). Please note that UNC support is not available on all platforms where LCL/LazUtils are hosted.
Path specification
A path specification as used on the local file systems For example: '/path/to/dir' or '\path\to\dir'. Relative paths, like './foo' or '.\foo', are resolved to the directory where the application executable is located.

ForceDirectoriesUTF8 calls ExtractFileDrive to get the disk or UNC host+share name used in Dir. No actions are performed if the return value from ExtractFileDrive is an empty device identifier, or the device does not have a valid root directory on the local file system. The return value is set to False.

ForceDirectories raises an EInOutError exception with the message in SCannotCreateEmptyDir when Dir contains an empty string ('').

ForceDirectoriesUTF8 converts path delimiters specified in Dir to the value required for the platform using ForcePathDelims (when needed).

Each directory found in Dir is checked using DirectoryExistsUTF8. CreateDirUTF8 is called if a directory does not already exist, and may exit with a return value of False if directory creation is not successful.

The return value is True if all directories in the path information already exist, or are successfully created in the function.

var bOk: Boolean;
// ...
bOk := ForceDirectoriesUTF8('\\capcom\telemetry\eva\bio');
bOk := ForceDirectoriesUTF8('//capcom/telemetry/eva/gps');
bOk := ForceDirectoriesUTF8('/home/jsmith/capcom/telemetry/eva/camera');
bOk := ForceDirectoriesUTF8('C:\capcom\telemetry\eva\era');

Errors

EIOnOutError
Raised when the directory name is an empty string (''); Message is SCannotCreateEmptyDir, and ErrorCode is set to 3.

See also

DirectoryExistsUTF8

  

Determine if the specified path exists on the local file system.

CreateDirUTF8

  

Creates a new directory with the specified name.

GetForcedPathDelims

  

Performs path delimiter substitutions for the specified file name.

ForceDirectory

  

Creates the specified directory if it does not already exist.

ExtractFileDrive

ExtractFilePath

DirectorySeparator


Version 3.2 Generated 2024-02-25 Home