|
<< Click to Display Table of Contents >> Navigation: 3. Script Language > Internet and Network > MCP. - MCP (Model-Context Protocol) server operations > File Tools - File and content operations > MCP Commands - FileTools |
MiniRobot Language (MRL) - MCP FileTools Commands
MCP.CTF / MCP.CopyToFile
Copy to File
Purpose
The MCP.CTF (CopyToFile) command copies a source file to a destination path. This command is useful for creating backups, duplicating files, and transferring files between locations. It supports both file system paths and can optionally overwrite existing destination files.
Syntax
MCP.CTF|$$SOURCE|$$DESTINATION
MCP.CTF|$$SOURCE|$$DESTINATION|$$OVERWRITE
Parameters
$$SOURCE - The full path to the source file to copy. The file must exist.
$$DESTINATION - The full path where the file should be copied. Parent directories are created if needed.
$$OVERWRITE - (Optional) Set to "true" or "1" to overwrite existing destination file. Default is "false".
Return Value
The command returns a success message on completion, including the number of bytes copied, or an error message if the operation fails.
Examples
' Example 1: Simple file copy
MCP.CTF|C:\Source\data.txt|C:\Backup\data.txt
' Example 2: Copy with overwrite
MCP.CTF|C:\Source\config.ini|C:\Dest\config.ini|true
' Example 3: Copy to new directory (auto-created)
' Parent directories are created automatically
MCP.CTF|C:\File.txt|C:\New\Path\To\File.txt
' Example 4: Backup workflow
VAR.SourceFile = "C:\Project\main.bas"
VAR.Timestamp = DAT.YYYYMMDD + "_" + DAT.HHMMSS
VAR.BackupPath = "C:\Backups\main_" + $$Timestamp + ".bas"
MCP.CTF|$$SourceFile|$$BackupPath
PRT.Backup created: $$BackupPath
' Example 5: Safe copy with existence check
MCP.AnalyzeFile|C:\Dest\file.txt|$$DestInfo
JSN.Get|$$DestInfo|exists|$$DestExists
IVV.$$DestExists!true
PRT.Destination exists, skipping copy
ELS.
MCP.CTF|C:\Source\file.txt|C:\Dest\file.txt
PRT.File copied successfully
EIF.
Remarks
The MCP.CTF command performs a binary copy, preserving the exact content of the source file including encoding and line endings. All file attributes are preserved in the copy, including timestamps (unless the operating system modifies them).
If the destination path contains directories that do not exist, they are automatically created. This makes it convenient to copy files to new directory structures without explicit directory creation steps.
By default, if the destination file already exists, the command will fail unless the overwrite parameter is set to "true". This prevents accidental file overwrites.
MCP.CTF and MCP.CopyToFile are aliases for the same command. You can use either form.
Error Conditions
The command will fail with an error if:
• The source file does not exist
• The destination file already exists and overwrite is not enabled
• Permission is denied for reading source or writing destination
• The source or destination path is invalid
• Insufficient disk space at destination
See also:
• MCP.GetContent - Get Content from File or Memory
• MCP.SetContent - Set Content to File or Memory
• MCP.AnalyzeFile - Analyze a File