DirectoryFileHandleProtocol
A handle suitable for directories.
- iOS
- 13.0+
- macOS
- 10.15+
- tvOS
- 13.0+
- watchOS
- 6.0+
protocol DirectoryFileHandleProtocol : FileHandleProtocol
Browse conforming typesIterating a directory
func listContents(
) -> DirectoryEntries Returns an
AsyncSequence
of entries in the open directory.
Opening files with managed lifecycles
Open files and directories at paths relative to the directory handle. These methods manage the lifecycle of the handles by closing them when the execute
closure returns.
func withFileHandle<Result>(forReadingAt: FilePath, options: OpenOptions.Read, execute: (_ read: ReadFileHandle) async throws -> Result
) async throws -> Result Opens the file at the given path and provides scoped read access to it.
func withFileHandle<Result>(forWritingAt: FilePath, options: OpenOptions.Write, execute: (_ write: WriteFileHandle) async throws -> Result
) async throws -> Result Opens the file at the given path and provides scoped write access to it.
func withFileHandle<Result>(forReadingAndWritingAt: FilePath, options: OpenOptions.Write, execute: (_ readWrite: ReadWriteFileHandle) async throws -> Result
) async throws -> Result Opens the file at the given path and provides scoped read-write access to it.
func withDirectoryHandle<Result>(atPath: FilePath, options: OpenOptions.Directory, execute: (_ directory: Self) async throws -> Result
) async throws -> Result Opens the directory at the given path and provides scoped access to it.
Opening files
Open files and directories at paths relative to the directory handle. These methods return the handle to the caller who is responsible for closing it.
func openFile(forReadingAt: FilePath, options: OpenOptions.Read
) async throws -> ReadFileHandle Opens the file at
path
for reading and returns a handle to it.func openFile(forWritingAt: FilePath, options: OpenOptions.Write
) async throws -> WriteFileHandle Opens the file at
path
for writing and returns a handle to it.func openFile(forReadingAndWritingAt: FilePath, options: OpenOptions.Write
) async throws -> ReadWriteFileHandle Opens the file at
path
for reading and writing and returns a handle to it.func openDirectory(atPath: FilePath, options: OpenOptions.Directory
) async throws -> Self Opens the directory at
path
and returns a handle to it.