FileExists?

BlitzMax Forums/BlitzMax Programming/FileExists?

Grey Alien(Posted 2006) [#1]
Am I being dumb (again)? But BMax doesn't seem to have a simple command to see if a file exists, so I made this:

Function ccFileExists%(filename$)
	Local file:TStream=OpenFile(filename)
	If file Then
		CloseStream file
		Return 1
	Else
		Return 0
	EndIf
End Function



Dreamora(Posted 2006) [#2]
FileType is the simple command for fileexist check.


GfK(Posted 2006) [#3]
Yup - FileType returns 0 for doesn't exist, 1 is a file, 2 is a folder. Same as in Blitz3D, I think.

Better to check for FileType() = 1, rather than FileType() <> 0, otherwise you could potentially end up trying to carry out file operations on a folder, which will cause errors.


Grey Alien(Posted 2006) [#4]
aha, good info thanks.