FileOperation
ConsoleMonster.FileSystem
A planned copy, move, delete or new folder that runs in the background with progress, conflict answers and a summary of the items that failed. Create one with FileOperation.Copy, FileOperation.Move, FileOperation.Delete, FileOperation.DeletePermanently or FileOperation.CreateFolder, then FileOperation.RunAsync it; nothing touches the disk before that.
Inheritance
- object
- FileOperation
Remarks
One failing item never stops the rest: access denied, a file in use or a path that's too long becomes a and the operation continues. tries those again. Cancellation stops after the file in progress, so no file is left half-written. Copies are written to a temporary name next to the destination and renamed into place when complete, so an existing file is only replaced by a whole one.
Usage
Explore 12 API references to this type
This type appears in these public API surfaces even when no hand-authored example is attached directly to the page.
Returned or exposed by 10
- Method CommanderModel.PlanCopy
- Method CommanderModel.PlanCreateFolder
- Method CommanderModel.PlanDelete
- Method CommanderModel.PlanMove
- Method FileOperation.Copy
- Method FileOperation.CreateFolder
- Method FileOperation.Delete
- Method FileOperation.DeletePermanently
- Method FileOperation.Move
- Method FileOperationResult.RetryFailed
Accepted by parameters 2
- Method CommanderModel.AfterOperation
- Method ICommanderHost.Start
Methods
public static FileOperation Copy(IEnumerable<string> sources, string destination, FileOperationOptions? options = null) #Copies files and folders. With several sources, or an existing folder as destination, the items keep their names inside it; a single source with any other destination is copied to that path, so report.csv to backup.csv copies under a new name. A relative destination is relative to the source's folder.
Parameters
- sources System.Collections.Generic.IEnumerable<string>
- Files and folders to copy.
- destination string
- The destination folder, or the new path for a single source.
- options ConsoleMonster.FileSystem.FileOperationOptions? = null
- Conflicts, timestamps, progress; defaults ask about conflicts and keep timestamps.
public static FileOperation CreateFolder(string path, FileOperationOptions? options = null) #Creates a folder and any missing parents. An existing file or folder at the path is an error.
Parameters
- path string
- The new folder.
- options ConsoleMonster.FileSystem.FileOperationOptions? = null
- Progress.
public static FileOperation Delete(IEnumerable<string> paths, FileOperationOptions? options = null) #Moves items to the recycle bin or trash (FileOperationOptions.Trash, or the platform's own). Where there's no trash for an item it fails with FileOperationErrorKind.TrashUnavailable and stays in place; it is never deleted permanently instead.
Parameters
- paths System.Collections.Generic.IEnumerable<string>
- Files and folders to delete.
- options ConsoleMonster.FileSystem.FileOperationOptions? = null
- Trash and progress.
public static FileOperation DeletePermanently(IEnumerable<string> paths, FileOperationOptions? options = null) #Deletes files and folders permanently, including read-only files. Symbolic links are removed, never followed.
Parameters
- paths System.Collections.Generic.IEnumerable<string>
- Files and folders to delete.
- options ConsoleMonster.FileSystem.FileOperationOptions? = null
- Progress.
public static FileOperation Move(IEnumerable<string> sources, string destination, FileOperationOptions? options = null) #Moves or renames files and folders, with the destination rules of FileOperation.Copy; Move(new[] { "a.txt" }, "b.txt") renames in place. Within one volume it's a rename; across volumes each file is copied and then removed.
Parameters
- sources System.Collections.Generic.IEnumerable<string>
- Files and folders to move.
- destination string
- The destination folder, or the new path for a single source.
- options ConsoleMonster.FileSystem.FileOperationOptions? = null
- Conflicts, timestamps, progress.
public Task<FileOperationResult> RunAsync(CancellationToken cancellationToken = default) #Runs the operation on a worker. It completes with a summary rather than throwing for item failures or cancellation.
Parameters
- cancellationToken System.Threading.CancellationToken = default
- Stops the operation after the item in progress.
public AppCommand ToAppCommand(string key, string? label = null, Action<FileOperationResult>? completed = null) #The operation as an app action, so it runs on the app's action runner with its cancel key and output log: each failed item and the final summary are written to the log.
Parameters
- key string
- The command key.
- label string? = null
- The label shown while it runs; the operation's kind when null.
- completed System.Action<ConsoleMonster.FileSystem.FileOperationResult>? = null
- Called with the result on the worker, before the action completes; post UI work back to the app thread.
Inherited Methods
Properties
public IReadOnlyList<string> Sources { get; } #The items it works on, as full paths.
public string? Destination { get; } #The destination as given: a folder, or the new path of a single copied or moved item.
public FileOperationOptions Options { get; } #The options, read when the operation runs.
public IReadOnlyList<string?> Targets { get; } #The full destination path of each source, in order; null for deletes.