Instance Methodswift-nio 2.72.0_NIOFileSystem
withTemporaryDirectory(prefix:options:execute:)
Create a temporary directory and removes it once the function returns.
FileSystemProtocol.swift:643- iOS
- 13.0+
- macOS
- 10.15+
- tvOS
- 13.0+
- watchOS
- 6.0+
func withTemporaryDirectory<Result>(prefix: FilePath? = nil, options: OpenOptions.Directory = OpenOptions.Directory(), execute: (_ directory: DirectoryFileHandle, _ path: FilePath) async throws -> Result) async throws -> Result
Parameters
Returns
The result of execute
.
You can use prefix
to specify the directory in which the temporary directory should be created. If prefix
is nil
then the value of temporaryDirectory
is used as the prefix.
The temporary directory, and all of its contents, is removed once execute
returns.
See also
var currentWorkingDirectory: FilePath
Returns the current working directory.
var temporaryDirectory: FilePath
Returns the path of the temporary directory.
Other members in extension
Instance members
func copyItem(at: FilePath, to: FilePath, shouldProceedAfterError: @escaping (_ source: DirectoryEntry, _ error: Error) async throws -> Void, shouldCopyItem: @escaping (_ source: DirectoryEntry, _ destination: FilePath) async -> Bool
) async throws Copies the item at the specified path to a new location.
func copyItem(at: FilePath, to: FilePath, strategy: CopyStrategy
) async throws Copies the item at the specified path to a new location.
func createDirectory(at: FilePath, withIntermediateDirectories: Bool
) async throws Create a directory at the given path.
func info(forFileAt: FilePath
) async throws -> FileInfo? Returns information about the file at the given path, if it exists; nil otherwise.
func openDirectory(atPath: FilePath
) async throws -> DirectoryFileHandle Opens the directory at
path
and returns a handle to it.func openFile(forReadingAt: FilePath
) async throws -> ReadFileHandle Opens the file at
path
for reading and returns a handle to it.func removeItem(at: FilePath
) async throws -> Int Deletes the file or directory (and its contents) at
path
.func withDirectoryHandle<Result>(atPath: FilePath, options: OpenOptions.Directory, execute: (_ directory: DirectoryFileHandle) async throws -> Result
) async throws -> Result Opens the directory at the given path and provides scoped 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 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-only 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-only access to it.