WebExeBuilder Documentation

fileCopy

Category: File Operations

Namespace: web.files.fileCopy

Description

Copies a file from one location to another. Automatically creates destination directories if needed and overwrites existing files.

Syntax

const success = await web.files.fileCopy({
    sourceFile: 'path/to/source.txt',
    destinationFile: 'path/to/destination.txt'
});

Parameters

  • sourceFile (required) - Path to the source file (relative or absolute)
  • destinationFile (required) - Path where the file should be copied (relative or absolute)

Returns

Promise<boolean> - Returns a promise that resolves with true if the file was copied successfully, false otherwise

Examples

Simple example

const success = await web.files.fileCopy({
    sourceFile: 'template.txt',
    destinationFile: 'document.txt'
});

if (success) {
    console.log('File copied successfully');
}

Create backup

const originalFile = 'data/settings.json';
const backupFile = 'backups/settings_backup.json';

const success = await web.files.fileCopy({
    sourceFile: originalFile,
    destinationFile: backupFile
});

console.log(success ? 'Backup created' : 'Backup failed');

Copy to different drive

// Copy from C: to D: drive
const success = await web.files.fileCopy({
    sourceFile: 'C:\\MyApp\\data.db',
    destinationFile: 'D:\\Backups\\data.db'
});

Use Cases

  • Create backup copies of files
  • Duplicate template files
  • Copy files to different locations
  • Archive important files
  • Replicate configuration files

Notes

  • Automatically creates destination directories if they don't exist
  • Overwrites destination file if it already exists
  • Source file remains unchanged
  • Returns false if source file doesn't exist
  • Both relative and absolute paths are supported