bool isEmptyDir(string dirPath)

Checks if the path is an empty directory.

FileEntry[] getFiles(
    string dir, 
    Flag!"hidden" hidden = Yes.hidden, 
    Flag!"recursively" recursively = No.recursively, 
    Flag!"absPath" saveAbsolutePath = Yes.absPath, 
    Flag!"enableFilter" enableFilter = No.enableFilter, 
    FileType[] includedTypes = []
)

Reads entries of the directory.

Parameters

dir

Directory for listing files.

hidden

Whether to include hidden files. Yes, by default.

recursively

Whether to search in subdirectories. No, by default.

saveAbsolutePath

Whether to store an absolute path or not. If Yes, a relative path of dir is converted to absolute. The parameter has no effect if dir is an absolute path. Has value Yes, by default.

enableFilter

Whether to filter by type. No, by default.

includedTypes

Types for including to final result. Used in conjunction with the previous parameter.

FileEntry[] getRegularFiles(
    string dir, 
    Flag!"hidden" hidden = Yes.hidden, 
    Flag!"recursively" recursively = No.recursively, 
    Flag!"absPath" saveAbsolutePath = Yes.absPath
)

Gets regular files from the directory.

Parameters

dir

Directory for listing regular files.

hidden

Whether to include hidden files. Yes, by default.

recursively

Whether to search in subdirectories. No, by default.

saveAbsolutePath

Whether to write the full path. Yes, by default.

FileEntry[] getDirectories(
    string dir, 
    Flag!"hidden" hidden = Yes.hidden, 
    Flag!"recursively" recursively = No.recursively, 
    Flag!"absPath" saveAbsolutePath = Yes.absPath
)

Gets directories from the directory.

Parameters

dir

Directory for listing directories.

hidden

Whether to include hidden files. Yes, by default.

recursively

Whether to search in subdirectories. No, by default.

saveAbsolutePath

Whether to write the full path. Yes, by default.

FileEntry[] getSymlinks(
    string dir, 
    Flag!"hidden" hidden = Yes.hidden, 
    Flag!"recursively" recursively = No.recursively, 
    Flag!"absPath" saveAbsolutePath = Yes.absPath
)

Gets symlinks from the directory.

Parameters

dir

Directory for listing symlinks.

hidden

Whether to include hidden files. Yes, by default.

recursively

Whether to search in subdirectories. No, by default.

saveAbsolutePath

Whether to write the full path. Yes, by default.

string readLinkRecurse(string link)

Returns read symlink path. If the symlink points to other symlink, the function returns path of the last symlink of the link chain.

bool isBrokenSymlink(string link, Flag!"recurse" recurse = No.recurse)

Checks if a file is a broken symbolic link is broken (whether indicates a non-existent location).

Parameters

link

Path to link.

recurse

Whether to check all nested symbolic links in a chain.

bool isPipe(in string path)

Checks if a path is a pipe file (FIFO).

bool isSocket(in string path)

Checks if a path is a socket.

bool isSymlink(in string path)

Checks if a path is a symbolic link.

bool isRegularFile(in string path)

Checks if a path is a regular file.

bool isRegularFile(in FileEntry entry)

Checks if a FileEntry object related to a regular file.

bool isBlockDevice(in string path)

Checks if a path is a block device.

bool isDir(in string path)

Checks if a path is a directory.

bool isDir(in FileEntry entry)

Checks if a FileEntry object related to a directory.

bool isSymlinkToDir(in string path)

Checks if the file is a symbolic link to a directory. The check is recursive (if the link points to a link).

Parameters

path

path fo file

Returns

whether a symbolic link is a link to a directory.

bool isCharDevice(in string path)

Checks if a path is a character device.

string getAbsolutePath(string path)

Returns absolute path for any raw path. Trailing slashes are removed.

void cp(
    string from, 
    string to, 
    Flag!"followLinks" followLinks = No.followLinks, 
    Flag!"passErrors" passErrors = No.passErrors, 
    Flag!"printErrors" printErrors = Yes.printErrors
)

Function for copying files and directories.

Parameters

from

source file

to

destination

followLinks

whether to follow symbolic links

passErrors

if No, the 'cp' function can throw exceptions else errors are ignored

printErrors

print information about errors or not (the parameter works if passErrors is Yes)

extern (C) int statx(
    int dfd, 
    const char* filename, 
    int flags, 
    uint mask, 
    statx_t* stx
)

This function returns information about a file, storing it in the buffer pointed to by statxbuf. System call of Linux 4.11+, see more: man statx This function is used in the high-level FileStat structure type.

auto STATX_TYPE

See

man statx

auto STATX_DEFAULT

Mask for stat field by default.

statx_t getStatX(string filepath)

Returns file information as statx_t. Wrapper for low level statx call.

stat_t getStat(string filepath)

High-level function for getting stat_t from file path.

FileType getFileTypeFromFileMode(uint mode) nothrow

Gets FileType by stat field 'mode'.

FileType getFileTypeFromFileMask(uint mask) nothrow

Gets FileType by the file mask obtained from stat field 'mode'.

string makeUnixFileModeLine(in uint mode)

The function returns file permissions in a string form (like -rwxrwxrwx)

string makeUnixFileModeLine(in FileStat st)

The function returns file permissions in a string form (like -rwxrwxrwx)

void hardlink(string original, string link)

Creates a new hard link (make a new name for a file, see man 2 link).

Parameters

original

Original file path.

link

New link location path.

bool exists(in string filepath) nothrow

Checks if the given file exists.

void truncate(string filepath, size_t size)

Truncate a file to a specified length.

Parameters

filepath

File to be resized.

size

New length in bytes.

void safeMkdir(string path)

Create a directory only if it doesn't exist.

void applyFileAdvise(File f, FileAdvice advice)

Predeclare an access pattern for file data.

Parameters

f

File object.

advice

Access patern.

See Also:

man 2 posix_fadvise

Public imports