Commodore‎ > ‎BASIC‎ > ‎Keywords‎ > ‎


Keyword Abbreviation Token (hex) Version(s) Classification
COPY CO{Shift+P} D3 4.x Command and Statement
ERR$ E{Shift+R} D3 3.5, 7.0 Function
COPY CO{Shift+P} F4 3.5, 7.0 Command and Statement

COPY originalFile D originalDrive ] [ { , | ON } U unitNumber ] ... [ , ItwoChar ] [ , R ] ... TO copyFile [ D copyDrive ] [ { , | ON } U unitNumber ] ...
Parameters Type Legal Value(s) Default Value Note(s)
originalFile  String  1 to 16 characters   Must not begin with @ 
originalDrive Integer 0 or 1 0 Non-literal must be enclosed in parentheses ()
copyFile String  1 to 16 characters   Must not begin with @ 
copyDrive Integer  0 or 1  originalDrive  Non-literal must be enclosed in parentheses ()
unitNumber Integer  8 ~ 11  Non-literal must be enclosed in parentheses () 
twoChar Char[2]  any    Must be two literal characters. 
Media file archiving.  Copy the originalFile to a new copyFile.

COPY duplicates originalFile by creating a new copyFile with the same file data.  The parameters originalFile and copyFile are the filenames of the original and duplicate files, respectively; they must (or will) be located on drives originalDrive and copyDrive respectively.  Both files must be on the same device (unitNumber).
Both filenames are required.  If either filename has more than 16 characters then STRING TO LONG ERROR will be generated instead.  If either filename has zero characters then MISSING FILE NAME ERROR occurs.  If either filename begins with an @ character, BASIC generates SYNTAX ERROR (even though the device may allow this).  Many devices will complain if either filename includes wild-card characters, like ? and *, but BASIC does not care.
Most devices allow orignalFile to be any "actual file" type, like SEQ, PRG, REL, or "real" (not GEOS VLIR) USR types, and the copyFile will be the same type.  Some devices may fail with REL files.  Few devices (if any) will copy CBM (1581-partition), DIR, or GEOS-USR types.
Some devices allow the copyFile to be a different (compatibile) type than the originalFile, but the way BASIC constructs the command sent to the device, most devices will report SYNTAX ERROR if you try to specify a file-type with COPY.  Thus if you want to copy PRG-type file to a SEQ-type duplicate, you have to use the "BASIC 2.0 method" by sending a properly constructed "copy" command (see a DOS reference manual).
Assuming the Syntax is good, BASIC transmits a command to the device (this updates ST) and reports no error unless the transmission failed (for example, DEVICE NOT PRESENT).  However, if the originalFile does not exist, the device will normally generate an error "62, FILE NOT FOUND,00,00".  If the copyFile already exists, the device will typically report "63, FILE EXISTS,00,00".  The device might generate an error in other cases (like write-protected media, or not enough space).  Be sure to check the device status with DS or DS$.
The drive numbers (originalDrive and copyDrive) may be different, as far as BASIC is concerned.  Many devices only allow drive number 0.
Although the Syntax allows unitNumber to be specified an unlimited number of times (before or after the TO preposition), only the last unitNumber given is used; the default is 8 if unitNumber is not given at all.
If a required parameter is omitted, or an expression (enclosed in parentheses) is not valid, or an expression is used without parentheses, SYNTAX ERROR occurs.  If any parameter is not the correct type (string or numeric) a TYPE MISMATCH ERROR will be generated.  Otherwise if a parameter is not a legal value (see table above), an ILLEGAL QUANTITY ERROR is generated.
Like all disk commands and statements, the Syntax is more flexible than shown above.  In particular, the parameters may be given in any order.  The general restrictions are: a comma (,) must not precede the first parameter, any non-literal value (a variable name or expression) must be enclosed in parentheses (), and do not supply the same parameter more than once.  Exceptions include the U and R parameters, which may used an unlimited number of times (R is ignored), and the twoChar parameter which must always be two literal characters (also ignored but may not be repeated). 
Like all disk-based commands, COPY restricts the "drive/parittion" numbers (originalDrive and copyDrive) to either 0 or 1 which often makes it unusable on a "disk" with multiple partitions.
Like all disk-based commands, COPY will reset DS$ and set the secret variable "DosFA" to the unitNumber.
COPY "ORG" TO "DUP"    : REM copy ORG as DUP; both on drive 0, unit 8
COPY "ORG",D1 TO "DUP" : REM copy ORG as DUP; both on drive 1, unit 8
COPY "ORG" TO "DUP",D1 : REM copy ORG (drive 0) to DUP (drive 1); both on unit 8
COPY "ORG" TO "DUP",U9 : REM copy ORG as DUP; both on drive 0, unit 9
COPY (M$)TO(B$),U(U)   : REM using variables
  Compare With  
  Contrast With  
  See Also  
© H2Obsession, 2014