mirror of
https://github.com/QB64-Phoenix-Edition/QB64pe.git
synced 2024-07-06 05:50:22 +00:00
33 lines
742 B
QBasic
33 lines
742 B
QBasic
|
|
||
|
'
|
||
|
' Duplicates the contents of one file into another
|
||
|
'
|
||
|
' Returns: 0 on success, 1 on error
|
||
|
FUNCTION CopyFile& (sourceFile$, destFile$)
|
||
|
DIM sourcefileNo, destFileNo
|
||
|
DIM fileLength AS _INTEGER64
|
||
|
|
||
|
E = 0
|
||
|
sourceFileNo = FREEFILE
|
||
|
OPEN sourceFile$ FOR BINARY as #sourceFileNo
|
||
|
if E = 1 THEN GOTO errorCleanup
|
||
|
|
||
|
fileLength = LOF(sourceFileNo)
|
||
|
|
||
|
destFileNo = FREEFILE
|
||
|
OPEN destFile$ FOR BINARY as #destFileNo
|
||
|
if E = 1 THEN GOTO errorCleanup
|
||
|
|
||
|
' Read the file in one go
|
||
|
buffer$ = SPACE$(fileLength)
|
||
|
|
||
|
GET #sourceFileNo, , buffer$
|
||
|
PUT #destFileNo, , buffer$
|
||
|
|
||
|
errorCleanup:
|
||
|
IF sourceFileNo <> 0 THEN CLOSE #sourceFileNo
|
||
|
IF destFileNo <> 0 THEN CLOSE #destFileNo
|
||
|
|
||
|
CopyFile& = E
|
||
|
END FUNCTION
|