vl-file-copy

AutoCad AutoLISP Functions

 
vl-file-copy
 
 
 

Copies or appends the contents of one file to another file

(vl-file-copy  source-file destination-file [append])

Copy or append the contents of one file to another file. The vl-file-copy function will not overwrite an existing file; it will only append to it.

Arguments

source-file

A string naming the file to be copied. If you do not specify a full path name, vl-file-copy looks in the AutoCAD default drawing directory.

destination-file

A string naming the destination file. If you do not specify a path name, vl-file-copy writes to the AutoCAD default drawing directory.

append

If specified and not nil, source-file is appended to destination-file (that is, copied to the end of the destination file).

Return Values

An integer, if the copy was successful; otherwise nil.

Some typical reasons for returning nil are

  • source-file is not readable
  • source-file is a directory
  • append? is absent or nil and destination-file exists
  • destination-file cannot be opened for output (that is, it is an illegal file name or a write-protected file)
  • source-file is the same as destination-file

Examples

Copy autoexec.bat to newauto.bat:

_$ (vl-file-copy "c:/autoexec.bat"
"c:/newauto.bat")
1417

Copy test.bat to newauto.bat:

_$ (vl-file-copy "c:/test.bat"
"c:/newauto.bat")
nil

The copy fails because newauto.bat already exists, and the append argument was not specified.

Repeat the previous command, but specify append:

_$ (vl-file-copy "c:/test.bat"
"c:/newauto.bat" T)
185

The copy is successful because T was specified for the append argument.