Table of Contents

Class CopyDirectory

Namespace
NanoByte.Common.Storage
Assembly
NanoByte.Common.dll

Copies the content of a directory to a new location preserving file timestamps, symlinks and hard links.

public class CopyDirectory : ReadDirectoryBase, ITask
Inheritance
CopyDirectory
Implements
Derived
Inherited Members
Extension Methods

Constructors

CopyDirectory(string, string)

Copies the content of a directory to a new location preserving file timestamps, symlinks and hard links.

public CopyDirectory(string sourcePath, string destinationPath)

Parameters

sourcePath string

The path of source directory. Must exist!

destinationPath string

The path of the target directory.

Properties

Name

A name describing the task in human-readable form.

public override string Name { get; }

Property Value

string

Overwrite

Overwrite existing files and directories at the destination path. This will even replace read-only files!

public bool Overwrite { get; init; }

Property Value

bool

UnitsByte

true if UnitsProcessed and UnitsTotal are measured in bytes; false if they are measured in generic units.

protected override bool UnitsByte { get; }

Property Value

bool

Methods

CopyFile(FileInfo, FileInfo)

Copies a single file from one location to another. Can be overridden to modify the copying behavior.

protected virtual void CopyFile(FileInfo sourceFile, FileInfo destinationFile)

Parameters

sourceFile FileInfo
destinationFile FileInfo

Exceptions

IOException

A problem occurred while copying the file.

UnauthorizedAccessException

Read access to the sourceFile or write access to the destinationFile is not permitted.

Execute()

The actual code to be executed.

protected override void Execute()

Remarks

State is automatically set to Started before calling this method, to Complete after a successful exit and to an appropriate error state in case on an exception. You can set additional TaskStates during execution.

Exceptions

OperationCanceledException

The operation was canceled.

IOException

The task ended with IOError.

WebException

The task ended with WebError.

HandleDirectory(DirectoryInfo)

Called once for every sub-directory below Source.

protected override void HandleDirectory(DirectoryInfo directory)

Parameters

directory DirectoryInfo

The directory to handle.

HandleFile(FileInfo, FileInfo?)

Called once for every file below Source.

protected override void HandleFile(FileInfo file, FileInfo? hardlinkTarget = null)

Parameters

file FileInfo

The file to handle.

hardlinkTarget FileInfo

A previously handled file that is hardlinked to file. May be null.