Code archives/File Utilities/CopyFile

This code has been declared by its author to be Public Domain code.

Download source code

CopyFile by Perturbatio2005
Copies a source file to the destination
Function CopyFile:Int(SourceFile:String, DestinationFile:String, AutoReplace:Int=False, BufSize:Int=4096)
	
	If FileType(SourceFile) <> 1 Then Return False
	If FileType(DestinationFile) = 1 And Not AutoReplace Then Return False
	
	Local SourceStream:TStream = OpenStream(SourceFile,True,False)
	Local DestStream:TStream = OpenStream(DestinationFile,False,True)
	
	CopyStream(SourceStream, DestStream, BufSize)
	CloseStream(SourceStream)
	CloseStream(DestStream)
	
	Return True
End Function

Comments

Grey Alien2005
Nice, it probably also works to copy read only CD-files to your computer and making them non-read only as you are not doing anything with the attributes.


Perturbatio2005
I updated it slightly to take into account the BufSize parameter of CopyStream.


D4NM4N2006
great!, and to think i was about 2 research writing my own :)

just what i was after!

thanks


tonyg2006
Can't you use BlitzMax's CopyFile function which does the same thing? Make sure you're updated.


Perturbatio2006
unless you need to do something specific that the BRL CopyFile doesn't do, I'd suggest using that instead (I wrote this before the BMax update).


Code Archives Forum