Blitz3D+ Command Reference

CopyFile file$,to$

Parameters

file$ - path and name of the file to copy

to$ - path and name to copy it to

Description

Copies a file to a new name or location.

Handy for backing up a save file before overwriting it, duplicating a template, or an installer-style tool moving data around. Both paths may be absolute or relative to the current directory, and the destination must include the file name, not just a folder.

If a file already exists at the destination it is overwritten.

CopyFile does not report failure (missing source, bad destination path), so if the copy matters, verify it afterwards - FileType tells you the destination exists and FileSize lets you compare sizes.

See also: DeleteFile, FileType, FileSize.

Example

; CopyFile Example
; ----------------

; Create an original file to copy
file=WriteFile("demo_original.txt")
WriteLine file,"Precious save-game data"
CloseFile file
Print "Created demo_original.txt ("+FileSize("demo_original.txt")+" bytes)"

; Copy it - a simple way to back up a save file
CopyFile "demo_original.txt","demo_backup.txt"
Print "Copied to demo_backup.txt ("+FileSize("demo_backup.txt")+" bytes)"

; Prove the copy holds the same text
file=ReadFile("demo_backup.txt")
Print "Backup contains: "+ReadLine$(file)
CloseFile file

; Clean up both demo files
DeleteFile "demo_original.txt"
DeleteFile "demo_backup.txt"
Print "Cleaned up both demo files"

Print ""
Print "Press any key to close the example"
WaitKey

End

Index