ForceDirectoriesUTF8 function
Creates the directories specified in Dir if they do not already exist.
Declaration
function ForceDirectoriesUTF8(const Dir: string): BooleanDescription
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
An experiment, built from Lazarus main 2dfa93c66e of 10-22-2026. Not the official Lazarus documentation.
