Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

COPY

The COPY keyword duplicates files within the bot’s drive storage, creating copies in the same or different directories.


Syntax

COPY "source" TO "destination"
result = COPY "source" TO "destination"

Parameters

ParameterTypeDescription
sourceStringPath to the file to copy
destinationStringPath for the new copy

Description

COPY creates a duplicate of a file in the bot’s storage. The original file remains unchanged. If the destination directory doesn’t exist, it’s created automatically.

Use cases include:

  • Creating backups before modifications
  • Duplicating templates for new users
  • Archiving files while keeping originals accessible
  • Organizing files into multiple locations

Examples

Basic File Copy

' Copy a file to a new location
COPY "templates/report.docx" TO "user-reports/report-copy.docx"
TALK "File copied successfully!"

Copy with Same Name

' Copy to different directory, keeping the same filename
COPY "documents/contract.pdf" TO "archive/contract.pdf"

Copy Before Editing

' Create backup before modifying
COPY "config/settings.json" TO "config/settings.json.backup"

' Now safe to modify original
content = READ "config/settings.json"
modified = REPLACE(content, "old_value", "new_value")
WRITE modified TO "config/settings.json"

TALK "Settings updated. Backup saved."

Copy Template for User

' Create user-specific copy of template
user_folder = "users/" + user.id
COPY "templates/welcome-kit.pdf" TO user_folder + "/welcome-kit.pdf"
TALK "Your welcome kit is ready!"

Copy with Timestamp

' Create timestamped copy
timestamp = FORMAT(NOW(), "YYYYMMDD-HHmmss")
COPY "reports/daily.csv" TO "archive/daily-" + timestamp + ".csv"
TALK "Report archived with timestamp"

Batch Copy

' Copy multiple files
files_to_copy = ["doc1.pdf", "doc2.pdf", "doc3.pdf"]

FOR EACH file IN files_to_copy
    COPY "source/" + file TO "destination/" + file
NEXT

TALK "Copied " + LEN(files_to_copy) + " files"

Return Value

Returns an object with copy details:

PropertyDescription
result.sourceOriginal file path
result.destinationNew file path
result.sizeFile size in bytes
result.copied_atTimestamp of copy operation

Error Handling

ON ERROR RESUME NEXT

COPY "documents/important.pdf" TO "backup/important.pdf"

IF ERROR THEN
    PRINT "Copy failed: " + ERROR_MESSAGE
    TALK "Sorry, I couldn't copy that file."
ELSE
    TALK "File copied successfully!"
END IF

Common Errors

ErrorCauseSolution
FILE_NOT_FOUNDSource doesn’t existVerify source path
PERMISSION_DENIEDAccess blockedCheck permissions
DESTINATION_EXISTSFile already existsUse different name or delete first
STORAGE_FULLNo space availableClean up storage

Behavior Notes

  • Overwrites by default: If destination exists, it’s replaced
  • Creates directories: Parent folders created automatically
  • Preserves metadata: File type and creation date preserved
  • Atomic operation: Copy completes fully or not at all

Configuration

No specific configuration required. Uses bot’s standard drive settings from config.csv:

name,value
drive-provider,seaweedfs
drive-url,http://localhost:8333
drive-bucket,my-bot

  • MOVE — Move or rename files
  • DELETE FILE — Remove files
  • READ — Read file contents
  • WRITE — Write file contents
  • LIST — List directory contents

Summary

COPY creates duplicates of files in storage. Use it for backups, templates, archiving, and organizing files. The original file is preserved, and destination directories are created automatically.