[bmx] CopyFile by Perturbatio [ 1+ years ago ]

Started by BlitzBot, June 29, 2017, 00:28:40

Previous topic - Next topic

BlitzBot

Title : CopyFile
Author : Perturbatio
Posted : 1+ years ago

Description : Copies a source file to the destination

Code :
Code (blitzmax) Select
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 Alien(Posted 1+ years ago)

 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.


Perturbatio(Posted 1+ years ago)

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


D4NM4N(Posted 1+ years ago)

 great!, and to think i was about 2 research writing my own :)just what i was after!thanks


tonyg(Posted 1+ years ago)

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


Perturbatio(Posted 1+ years ago)

 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).