Files

sealed trait Files[F[_]]

Provides operations related to working with files in the effect F.

An instance is available for any effect F which has an Async[F] instance.

The operations on this trait are implemented for both the JVM and Node.js. Some operations only work on POSIX file systems, though such methods generally have "Posix" in their names (e.g. getPosixPermissions). A small number of methods are only available on the JVM (e.g. variant of list which takes a glob pattern) and are indicated as such in their ScalaDoc.

Companion:
object
class Object
trait Matchable
class Any

Value members

Abstract methods

def copy(source: Path, target: Path, flags: CopyFlags): F[Unit]

Copies the source to the target, following any directives supplied in the flags. By default, an error occurs if the target already exists, though this can be overriden via CopyFlag.ReplaceExisting.

Copies the source to the target, following any directives supplied in the flags. By default, an error occurs if the target already exists, though this can be overriden via CopyFlag.ReplaceExisting.

def createDirectories(path: Path, permissions: Option[Permissions]): F[Unit]

Creates the specified directory and any parent directories, using the supplied permissions for any directories that get created as a result of this operation. For example if /a exists and createDirectories(Path("/a/b/c"), Some(p)) is called, /a/b and /a/b/c are created with permissions set to p on each (and the permissions of /a remain unmodified).

Creates the specified directory and any parent directories, using the supplied permissions for any directories that get created as a result of this operation. For example if /a exists and createDirectories(Path("/a/b/c"), Some(p)) is called, /a/b and /a/b/c are created with permissions set to p on each (and the permissions of /a remain unmodified).

def createDirectory(path: Path, permissions: Option[Permissions]): F[Unit]

Creates the specified directory with the specified permissions. Fails if the parent path does not already exist.

Creates the specified directory with the specified permissions. Fails if the parent path does not already exist.

def createFile(path: Path, permissions: Option[Permissions]): F[Unit]

Creates the specified file with the specified permissions. Fails if the parent path does not already exist.

Creates the specified file with the specified permissions. Fails if the parent path does not already exist.

def createTempDirectory(dir: Option[Path], prefix: String, permissions: Option[Permissions]): F[Path]

Creates a temporary directory. The created directory is not automatically deleted - it is up to the operating system to decide when the file is deleted. Alternatively, use tempDirectory to get a resource which deletes upon resource finalization.

Creates a temporary directory. The created directory is not automatically deleted - it is up to the operating system to decide when the file is deleted. Alternatively, use tempDirectory to get a resource which deletes upon resource finalization.

Value parameters:
dir

the directory which the temporary directory will be created in. Pass none to use the default system temp directory

permissions

permissions to set on the created directory

prefix

the prefix string to be used in generating the directory's name

def createTempFile(dir: Option[Path], prefix: String, suffix: String, permissions: Option[Permissions]): F[Path]

Creates a temporary file. The created file is not automatically deleted - it is up to the operating system to decide when the file is deleted. Alternatively, use tempFile to get a resource which deletes upon resource finalization.

Creates a temporary file. The created file is not automatically deleted - it is up to the operating system to decide when the file is deleted. Alternatively, use tempFile to get a resource which deletes upon resource finalization.

Value parameters:
dir

the directory which the temporary file will be created in. Pass none to use the default system temp directory

permissions

permissions to set on the created file

prefix

the prefix string to be used in generating the file's name

suffix

the suffix string to be used in generating the file's name

User's current working directory

User's current working directory

def delete(path: Path): F[Unit]

Deletes the specified file or empty directory, failing if it does not exist.

Deletes the specified file or empty directory, failing if it does not exist.

def deleteIfExists(path: Path): F[Boolean]

Deletes the specified file or empty directory, passing if it does not exist.

Deletes the specified file or empty directory, passing if it does not exist.

def deleteRecursively(path: Path, followLinks: Boolean): F[Unit]

Deletes the specified file or directory. If the path is a directory and is non-empty, its contents are recursively deleted. Symbolic links are followed when followLinks is true.

Deletes the specified file or directory. If the path is a directory and is non-empty, its contents are recursively deleted. Symbolic links are followed when followLinks is true.

def exists(path: Path, followLinks: Boolean): F[Boolean]

Returns true if the specified path exists. Symbolic links are followed when followLinks is true. For example, if the symbolic link foo points to bar and bar does not exist, exists(Path("foo"), true) returns false but exists(Path("foo"), false) returns true.

Returns true if the specified path exists. Symbolic links are followed when followLinks is true. For example, if the symbolic link foo points to bar and bar does not exist, exists(Path("foo"), true) returns false but exists(Path("foo"), false) returns true.

Gets BasicFileAttributes for the supplied path. Symbolic links are not followed when followLinks is true.

Gets BasicFileAttributes for the supplied path. Symbolic links are not followed when followLinks is true.

def getLastModifiedTime(path: Path, followLinks: Boolean): F[FiniteDuration]

Gets the last modified time of the supplied path. The last modified time is represented as a duration since the Unix epoch. Symbolic links are followed when followLinks is true.

Gets the last modified time of the supplied path. The last modified time is represented as a duration since the Unix epoch. Symbolic links are followed when followLinks is true.

Gets the POSIX attributes for the supplied path. Symbolic links are followed when followLinks is true.

Gets the POSIX attributes for the supplied path. Symbolic links are followed when followLinks is true.

def getPosixPermissions(path: Path, followLinks: Boolean): F[PosixPermissions]

Gets the POSIX permissions of the supplied path. Symbolic links are followed when followLinks is true.

Gets the POSIX permissions of the supplied path. Symbolic links are followed when followLinks is true.

def isDirectory(path: Path, followLinks: Boolean): F[Boolean]

Returns true if the supplied path exists and is a directory. Symbolic links are followed when followLinks is true.

Returns true if the supplied path exists and is a directory. Symbolic links are followed when followLinks is true.

def isExecutable(path: Path): F[Boolean]

Returns true if the supplied path exists and is executable.

Returns true if the supplied path exists and is executable.

def isHidden(path: Path): F[Boolean]

Returns true if the supplied path is a hidden file (note: may not check for existence).

Returns true if the supplied path is a hidden file (note: may not check for existence).

def isReadable(path: Path): F[Boolean]

Returns true if the supplied path exists and is readable.

Returns true if the supplied path exists and is readable.

def isRegularFile(path: Path, followLinks: Boolean): F[Boolean]

Returns true if the supplied path is a regular file. Symbolic links are followed when followLinks is true.

Returns true if the supplied path is a regular file. Symbolic links are followed when followLinks is true.

def isSameFile(path1: Path, path2: Path): F[Boolean]

Returns true if the supplied paths reference the same file.

Returns true if the supplied paths reference the same file.

def isWritable(path: Path): F[Boolean]

Returns true if the supplied path exists and is writable.

Returns true if the supplied path exists and is writable.

def list(path: Path): Stream[F, Path]

Gets the contents of the specified directory.

Gets the contents of the specified directory.

def move(source: Path, target: Path, flags: CopyFlags): F[Unit]

Moves the source to the target, following any directives supplied in the flags. By default, an error occurs if the target already exists, though this can be overriden via CopyFlag.ReplaceExisting.

Moves the source to the target, following any directives supplied in the flags. By default, an error occurs if the target already exists, though this can be overriden via CopyFlag.ReplaceExisting.

def open(path: Path, flags: Flags): Resource[F, FileHandle[F]]

Creates a FileHandle for the file at the supplied Path. The supplied flags indicate the mode used when opening the file (e.g. read, write, append) as well as the ability to specify additional options (e.g. automatic deletion at process exit).

Creates a FileHandle for the file at the supplied Path. The supplied flags indicate the mode used when opening the file (e.g. read, write, append) as well as the ability to specify additional options (e.g. automatic deletion at process exit).

def readAll(path: Path, chunkSize: Int, flags: Flags): Stream[F, Byte]

Reads all bytes from the file specified, reading in chunks up to the specified limit, and using the supplied flags to open the file.

Reads all bytes from the file specified, reading in chunks up to the specified limit, and using the supplied flags to open the file.

def readCursor(path: Path, flags: Flags): Resource[F, ReadCursor[F]]

Returns a ReadCursor for the specified path, using the supplied flags when opening the file.

Returns a ReadCursor for the specified path, using the supplied flags when opening the file.

def readRange(path: Path, chunkSize: Int, start: Long, end: Long): Stream[F, Byte]

Reads a range of data synchronously from the file at the specified path. start is inclusive, end is exclusive, so when start is 0 and end is 2, two bytes are read.

Reads a range of data synchronously from the file at the specified path. start is inclusive, end is exclusive, so when start is 0 and end is 2, two bytes are read.

def realPath(path: Path): F[Path]

Returns the real path i.e. the actual location of path. The precise definition of this method is implementation dependent but in general it derives from this path, an absolute path that locates the same file as this path, but with name elements that represent the actual name of the directories and the file.

Returns the real path i.e. the actual location of path. The precise definition of this method is implementation dependent but in general it derives from this path, an absolute path that locates the same file as this path, but with name elements that represent the actual name of the directories and the file.

def setFileTimes(path: Path, lastModified: Option[FiniteDuration], lastAccess: Option[FiniteDuration], creationTime: Option[FiniteDuration], followLinks: Boolean): F[Unit]

Sets the last modified, last access, and creation time fields of the specified path.

Sets the last modified, last access, and creation time fields of the specified path.

Times which are supplied as None are not modified. E.g., setTimes(p, Some(t), Some(t), None, false) sets the last modified and last access time to t and does not change the creation time.

If the path is a symbolic link and followLinks is true, the target of the link as times set. Otherwise, the link itself has times set.

def setPosixPermissions(path: Path, permissions: PosixPermissions): F[Unit]

Sets the POSIX permissions for the supplied path. Fails on non-POSIX file systems.

Sets the POSIX permissions for the supplied path. Fails on non-POSIX file systems.

def size(path: Path): F[Long]

Gets the size of the supplied path, failing if it does not exist.

Gets the size of the supplied path, failing if it does not exist.

def tail(path: Path, chunkSize: Int, offset: Long, pollDelay: FiniteDuration): Stream[F, Byte]

Returns an infinite stream of data from the file at the specified path. Starts reading from the specified offset and upon reaching the end of the file, polls every pollDuration for additional updates to the file.

Returns an infinite stream of data from the file at the specified path. Starts reading from the specified offset and upon reaching the end of the file, polls every pollDuration for additional updates to the file.

Read operations are limited to emitting chunks of the specified chunk size but smaller chunks may occur.

If an error occurs while reading from the file, the overall stream fails.

def tempDirectory(dir: Option[Path], prefix: String, permissions: Option[Permissions]): Resource[F, Path]

Creates a temporary directory and deletes it upon finalization of the returned resource.

Creates a temporary directory and deletes it upon finalization of the returned resource.

Value parameters:
dir

the directory which the temporary directory will be created in. Pass in None to use the default system temp directory

permissions

permissions to set on the created file

prefix

the prefix string to be used in generating the directory's name

Returns:

a resource containing the path of the temporary directory

def tempFile(dir: Option[Path], prefix: String, suffix: String, permissions: Option[Permissions]): Resource[F, Path]

Creates a temporary file and deletes it upon finalization of the returned resource.

Creates a temporary file and deletes it upon finalization of the returned resource.

Value parameters:
dir

the directory which the temporary file will be created in. Pass in None to use the default system temp directory

permissions

permissions to set on the created file

prefix

the prefix string to be used in generating the file's name

suffix

the suffix string to be used in generating the file's name

Returns:

a resource containing the path of the temporary file

def userHome: F[Path]

User's home directory

User's home directory

def walk(start: Path, maxDepth: Int, followLinks: Boolean): Stream[F, Path]

Creates a stream of paths contained in a given file tree down to a given depth.

Creates a stream of paths contained in a given file tree down to a given depth.

def writeAll(path: Path, flags: Flags): (F, Byte) => Nothing

Writes all data to the file at the specified path, using the specified flags to open the file.

Writes all data to the file at the specified path, using the specified flags to open the file.

def writeCursor(path: Path, flags: Flags): Resource[F, WriteCursor[F]]

Returns a WriteCursor for the specified path.

Returns a WriteCursor for the specified path.

Returns a WriteCursor for the specified file handle.

Returns a WriteCursor for the specified file handle.

If append is true, the offset is initialized to the current size of the file.

def writeRotate(computePath: F[Path], limit: Long, flags: Flags): (F, Byte) => Nothing

Writes all data to a sequence of files, each limited in size to limit.

Writes all data to a sequence of files, each limited in size to limit.

The computePath operation is used to compute the path of the first file and every subsequent file. Typically, the next file should be determined by analyzing the current state of the filesystem -- e.g., by looking at all files in a directory and generating a unique name.

Concrete methods

def copy(source: Path, target: Path): F[Unit]

Copies the source to the target, failing if source does not exist or the target already exists. To replace the existing instead, use copy(source, target, CopyFlags(CopyFlag.ReplaceExisting)).

Copies the source to the target, failing if source does not exist or the target already exists. To replace the existing instead, use copy(source, target, CopyFlags(CopyFlag.ReplaceExisting)).

def createDirectories(path: Path): F[Unit]

Creates the specified directory and any non-existant parent directories.

Creates the specified directory and any non-existant parent directories.

def createDirectory(path: Path): F[Unit]

Creates the specified directory. Fails if the parent path does not already exist.

Creates the specified directory. Fails if the parent path does not already exist.

def createFile(path: Path): F[Unit]

Creates the specified file. Fails if the parent path does not already exist.

Creates the specified file. Fails if the parent path does not already exist.

Creates a temporary directory. The created directory is not automatically deleted - it is up to the operating system to decide when the file is deleted. Alternatively, use tempDirectory to get a resource which deletes upon resource finalization.

Creates a temporary directory. The created directory is not automatically deleted - it is up to the operating system to decide when the file is deleted. Alternatively, use tempDirectory to get a resource which deletes upon resource finalization.

Creates a temporary file. The created file is not automatically deleted - it is up to the operating system to decide when the file is deleted. Alternatively, use tempFile to get a resource, which is deleted upon resource finalization.

Creates a temporary file. The created file is not automatically deleted - it is up to the operating system to decide when the file is deleted. Alternatively, use tempFile to get a resource, which is deleted upon resource finalization.

def deleteRecursively(path: Path): F[Unit]

Deletes the specified file or directory. If the path is a directory and is non-empty, its contents are recursively deleted. Symbolic links are not followed (but are deleted).

Deletes the specified file or directory. If the path is a directory and is non-empty, its contents are recursively deleted. Symbolic links are not followed (but are deleted).

def exists(path: Path): F[Boolean]

Returns true if the specified path exists. Symbolic links are followed -- see the overload for more details on links.

Returns true if the specified path exists. Symbolic links are followed -- see the overload for more details on links.

Gets BasicFileAttributes for the supplied path. Symbolic links are not followed.

Gets BasicFileAttributes for the supplied path. Symbolic links are not followed.

Gets the last modified time of the supplied path. The last modified time is represented as a duration since the Unix epoch. Symbolic links are followed.

Gets the last modified time of the supplied path. The last modified time is represented as a duration since the Unix epoch. Symbolic links are followed.

Gets the POSIX attributes for the supplied path. Symbolic links are not followed.

Gets the POSIX attributes for the supplied path. Symbolic links are not followed.

Gets the POSIX permissions of the supplied path. Symbolic links are followed.

Gets the POSIX permissions of the supplied path. Symbolic links are followed.

def isDirectory(path: Path): F[Boolean]

Returns true if the supplied path exists and is a directory. Symbolic links are followed.

Returns true if the supplied path exists and is a directory. Symbolic links are followed.

def isRegularFile(path: Path): F[Boolean]

Returns true if the supplied path is a regular file. Symbolic links are followed.

Returns true if the supplied path is a regular file. Symbolic links are followed.

def move(source: Path, target: Path): F[Unit]

Moves the source to the target, failing if source does not exist or the target already exists. To replace the existing instead, use move(source, target, CopyFlags(CopyFlag.ReplaceExisting)).

Moves the source to the target, failing if source does not exist or the target already exists. To replace the existing instead, use move(source, target, CopyFlags(CopyFlag.ReplaceExisting)).

def readAll(path: Path): Stream[F, Byte]

Reads all bytes from the file specified.

Reads all bytes from the file specified.

Creates a temporary directory and deletes it upon finalization of the returned resource.

Creates a temporary directory and deletes it upon finalization of the returned resource.

Creates a temporary file and deletes it upon finalization of the returned resource.

Creates a temporary file and deletes it upon finalization of the returned resource.

def walk(start: Path): Stream[F, Path]

Creates a stream of paths contained in a given file tree. Depth is unlimited.

Creates a stream of paths contained in a given file tree. Depth is unlimited.

def writeAll(path: Path): (F, Byte) => Nothing

Writes all data to the file at the specified path.

Writes all data to the file at the specified path.

The file is created if it does not exist and is truncated. Use writeAll(path, Flags.Append) to append to the end of the file, or pass other flags to further customize behavior.