View source code Display the source code in std/file.d from which this page was generated on github. Improve this page Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using local clone. Page wiki View or edit the community-maintained wiki page associated with this page.

Module std.file

Utilities for manipulating files and scanning directories. Functions in this module handle files as a unit, e.g., read or write one file at a time. For opening files and manipulating them via handles refer to module std.stdio.

Functions

Name Description
append Appends buffer to file name.
attrIsDir Returns whether the given file attributes are for a directory.
attrIsFile Returns whether the given file attributes are for a file.
attrIsSymlink Returns whether the given file attributes are for a symbolic link.
chdir Change directory to pathname.
copy Copy file from to file to. File timestamps are preserved. File attributes are preserved, if preserve equals PreserveAttributes.yes. On Windows only PreserveAttributes.yes (the default on Windows) is supported. If the target file exists, it is overwritten.
dirEntries Convenience wrapper for filtering file names with a glob pattern.
dirEntries Returns an input range of DirEntry that lazily iterates a given directory, also provides two ways of foreach iteration. The iteration variable can be of type string if only the name is needed, or DirEntry if additional details are needed. The span mode dictates the how the directory is traversed. The name of the each directory entry iterated contains the absolute path.
exists Returns whether the given file (or directory) exists.
getAttributes Returns the attributes of the given file.
getcwd Get the current working directory.
getLinkAttributes If the given file is a symbolic link, then this returns the attributes of the symbolic link itself rather than file that it points to. If the given file is not a symbolic link, then this function returns the same result as getAttributes.
getSize Get size of file name in bytes.
getTimes Get the access and modified times of file or folder name.
getTimesWin This function is Windows-Only.
isDir Returns whether the given file is a directory.
isFile Returns whether the given file (or directory) is a file.
isSymlink Returns whether the given file is a symbolic link.
mkdir Make directory pathname.
mkdirRecurse Make directory and all parent directories as needed.
read Read entire contents of file name and returns it as an untyped array. If the file size is larger than upTo, only upTo bytes are read.
readLink This function is Posix-Only.
readText Read and validates (using std.utf.validate) a text file. S can be a type of array of characters of any width and constancy. No width conversion is performed; if the width of the characters in file name is different from the width of elements of S, validation will fail.
remove Delete file name.
rename Rename file from to to. If the target file exists, it is overwritten.
rmdir Remove directory pathname.
rmdirRecurse Remove directory and all of its content and subdirectories, recursively.
setAttributes Set the attributes of the given file.
setTimes Set access/modified times of file or folder name.
slurp Reads an entire file into an array.
symlink This function is Posix-Only.
tempDir Returns the path to a directory for temporary files.
thisExePath Returns the full path of the current executable.
timeLastModified Returns the time that the given file was last modified. If the file does not exist, returns returnIfMissing.
timeLastModified Returns the time that the given file was last modified.
write Write buffer to file name.

Classes

Name Description
FileException Exception thrown for file I/O errors.

Structs

Name Description
DirEntry Info on a file, similar to what you'd get from stat on a Posix system.

Enums

Name Description
SpanMode Dictates directory spanning policy for dirEntries (see below).

Global variables

Name Type Description
preserveAttributesDefault Flag!("preserveAttributes") Defaults to PreserveAttributes.yes on Windows, and the opposite on all other platforms.

Authors

Walter Bright, Andrei Alexandrescu, Jonathan M Davis

License

Boost License 1.0.

Comments