ubyte[] read(string filepath, ssize_t size = -1, ssize_t offset = 0)
Reads the contents of the specified file as a byte array.
Parameters
| path | Path to the file. |
| size | Maximum number of bytes to read. If size < 0, the entire file is read. |
| offset | Byte offset from which to start reading. |
Returns
the file bytes.
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. |
See Also:
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 isRegularFile(ref const FileEntry entry)
Checks if a FileEntry object related to a regular file.
bool isBlockDevice(ref const FileEntry entry)
Checks if a FileEntry object related to a block device.
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.
string getAbsolutePath(string path)
Returns absolute path for any raw path. Trailing slashes are removed.
void copyRecurse(
string from,
string to,
Flag!"followLinks" followLinks = No.followLinks,
Flag!"keepMetaData" keepMetaData = No.keepMetaData,
Flag!"passErrors" passErrors = No.passErrors,
Flag!"printErrors" printErrors = Yes.printErrors
)
Function for copying files and directories. Files can have multiple hard links, and that is accounted for.
Parameters
| from | source file |
| to | destination |
| followLinks | whether to follow symbolic links |
| keepMetaData | Whether to copy access mode, timestamps, x-attributes. |
| passErrors | if No, the 'copyRecurse()' function can throw exceptions else errors are ignored |
| printErrors | print information about errors or not (the parameter works if passErrors is Yes) |
void copyMetaData(string src, string dst)
Copies access mode, timestamps, x-attributes from the 1st file to the 2nd file.
auto STATX_TYPE
See
man statx
auto STATX_DEFAULT
Mask for stat field by default.
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(const FileStat st)
The function returns file permissions in a string form (like -rwxrwxrwx)
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
void applyFileAdvise(int fd, FileAdvice advice)
Predeclare an access pattern for file data.
Parameters
| fd | Open file descriptor. |
| advice | Access patern. |
See Also:
man 2 posix_fadvise
Public imports
- std.typecons
- amalthea.libcore
Enums
| FileType | |
| FileAdvice |
Variables
| STATX_TYPE | |
| STATX_DEFAULT |
Functions
Structs
| DirReader | |
| FileEntry | |
| statx_t | |
| FileStat |
Classes
| DesktopEntry | |
| xattr |
The module provides many function related to files.