Copy file

BlitzMax Forums/BlitzMax Programming/Copy file

Tachyon(Posted 2005) [#1]
I need to have BMax copy files from one directory to another. I don't see a File System command to perform this. Any suggestions?


Perturbatio(Posted 2005) [#2]
either use
System_ "copy c:\myfile.txt d:\myfile.txt"


or read it into a stream and write it out elsewhere


Tachyon(Posted 2005) [#3]
Thanx Pert


Perturbatio(Posted 2005) [#4]
in fact, I'm feeling nice:
Function CopyFile:Int(SourceFile:String, DestinationFile:String, AutoReplace=False)
	
	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)
	CloseStream(SourceStream)
	CloseStream(DestStream)
	
	Return True
End Function



Tachyon(Posted 2005) [#5]
Pert- that 2nd piece of sample code was just what I needed. Thanx again.