bmx-ng / brl.mod

BlitzMax Runtime Libraries, for BlitzMax NG.
12 stars 11 forks source link

add FileExists function or use FileSize =-1? also, one other thing #307

Closed zarosath closed 8 months ago

zarosath commented 10 months ago

i were not able to compile successfully adding a FileExists function and using it from the FileSystem module of FileSystem.bmx in Linux.bmx from brl.Platform.mod, module didnt match the commandline module?

if statements of a non-existent FileExists function has been included in a release or two so im asking should there a FileExists function?

the other issue is from the same source file linux.bmx

Local cpustat:TStream = ReadFile("/proc/stat") i had to change this line from cpustat:stream to TStream to compile successfully.

GWRon commented 10 months ago

I assume one could add something like this:

Function FileExists:Int(url:string) Inline
  Return FileType(url) = FILETYPE_FILE
End Function

Function DirectoryExists:Int(url:string) Inline
  Return FileType(url) = FILETYPE_DIR
End Function

That way it should not add much overhead to the code but provide "convenience functions" people might know from other libraries

GWRon commented 10 months ago

Brucey added FileExists() with commit https://github.com/bmx-ng/brl.mod/commit/55f4ee5b12336b564980ad1a31f44ec241643a01

@woollybah is it correct to check against FILETYPE_NONE instead of FILETYPE_FILE ? For now also valid existing directories would return True for a given uri. (issue originally mentioned by @Scaremonger at discord)

VBA has FileExists() and FolderExists() https://learn.microsoft.com/de-de/office/vba/language/reference/user-interface-help/fileexists-method https://learn.microsoft.com/de-de/office/vba/language/reference/user-interface-help/folderexists-method

.net has also two different functions: https://learn.microsoft.com/en-us/dotnet/api/system.io.file.exists?view=net-8.0 https://learn.microsoft.com/en-us/dotnet/api/system.io.directory.exists?view=net-8.0