CopyFile Activity

Purpose: This activity copies a file to a new location. The source file remains unchanged, and a copy is created at the destination path. This is useful for backing up files, creating duplicates, or moving files to different locations while preserving the original.

Input Properties

SourcePath

The source file path to copy. This must be an existing file that is accessible and readable.

Type: string

Required: Yes

Example: "C:\Data\Source.txt"

DestinationPath

The destination file path where the copy will be created. The destination directory will be created if it doesn't exist.

Type: string

Required: Yes

Example: "C:\Backup\Source.txt"

Overwrite

True to overwrite existing files; false to fail if destination exists.

Type: bool

Default: false

Note: If set to false and the destination file already exists, the copy operation will fail.

Output Properties

Success

True if the file was copied successfully, false otherwise.

Type: bool

Note: Returns false if the source or destination path is null or empty, if the source file does not exist, if the destination file exists and Overwrite is false, if access is denied, or if an error occurs.

Usage Example

Scenario: Copy a file to a backup location

Configuration:
- SourcePath: "C:\Data\Document.txt"
- DestinationPath: "C:\Backup\Document.txt"
- Overwrite: false

Result:
- Success: true

Scenario: Copy with overwrite enabled

Configuration:
- SourcePath: "C:\Data\Report.xlsx"
- DestinationPath: "C:\Archive\Report.xlsx"
- Overwrite: true

Result:
- Success: true (even if destination exists)

Error Handling

Important: The activity handles errors gracefully:

  • If SourcePath or DestinationPath is null or empty, Success will be false
  • If the source file does not exist (FileNotFoundException), Success will be false
  • If access is denied (UnauthorizedAccessException), Success will be false
  • If an IO error occurs (IOException), Success will be false
  • If any other exception occurs, Success will be false
  • The activity does not throw exceptions - errors are indicated by the Success output

Always check the Success output to verify if the file was copied successfully.

Important Notes

  • The SourcePath must point to an existing file that is accessible and readable
  • The destination directory will be created automatically if it doesn't exist
  • If Overwrite is false and the destination file exists, the operation will fail
  • The source file remains unchanged after copying
  • Large files may take time to copy - consider file size when using this activity
  • Ensure the destination location has sufficient disk space

Related Activities