Odd Error with Readstream...

BlitzMax Forums/BlitzMax Programming/Odd Error with Readstream...

Stu_ovine(Posted 2008) [#1]
Can anyone see why this would fail to check for the existence of a named file ?

Im not do an excessive amount of loading - randomly it errors with cant not find......


Function Check(file:String) 
Local thisStream:TStream = ReadStream(file) 
	If Not ReadStream(file) Then
		RuntimeError("Can not find " + String(file)) 
		End
	EndIf
	
	thisstream.Close
End Function



ziggy(Posted 2008) [#2]
If you want to check if a file exists:
Function FileExist:int(File:String)
    If FileSize(File) = -1 Then Return False
    Return true
End Function


A ReadStream will create the file.


Stu_ovine(Posted 2008) [#3]
Possibly im using readstream twice instead of once ? I've changed it to check for a null stream instead...


Function Check(file:String) 

	Local thisStream:TStream = ReadStream(file) 
	If thisStream = Null Then
		RuntimeError("Can not find " + String(file)) 
		End
	EndIf
	
	thisstream.Close
	
End Function




TomToad(Posted 2008) [#4]
Possibly should use
If FileType(file) <> 1

That way, it'll post the error if the file doesn't exist or it is a directory instead of a readable file.


Stu_ovine(Posted 2008) [#5]
IM not actually using a file, its from a stream so filetype wont work.