[Implemented] 2 simple & useful functions needed

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

[Implemented] 2 simple & useful functions needed

Post by BackupUser »

Restored from previous forum. Originally posted by lanael.


FileExists( Filename$ )
Test if a file exists
return 1 if found, 0 otherwise.

Milliseconds()
Return the number of milliseconds since the computer starts
( I think every OS has it )


/* don't believe, just think */
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Justin.

This is my version of fileexist, there are other alternatives.

Code: Select all

#HFILE_ERROR=-1

sof.OFSTRUCT

global sof

;test if a file exists
;Returns: true if exists, false otherwise
procedure fileexist(file$)
  if OpenFile_(file$,@sof,#OF_EXIST)=#HFILE_ERROR 
    procedurereturn 0
  else
    procedurereturn 1
  endif
endprocedure

BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by lanael.

Oh, ok.
I've not looked enough on these '_'-suffixed functions (kind of low-level ?? )
But a filexist function included in the language would be fine !

Thanks anyway.

/* don't believe, just think */
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.

> FileExists( Filename$ )

If FileSize(filename$)=-1 : Debug "File does NOT exist!" : EndIf

> Milliseconds()

For Windows only: GetTickCount_()
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Pupil.

You can also use the command FileSize() to check if a file exist or not. The command returns -1 if file doesn't exist and -2 if the filename you've provided is a directory name..

example:

Code: Select all

If FileSize(filename$) = -1
  ; File doesn't exist
EndIf
If you want the milliseconds elapsed since computer was turned on you can use this:

Code: Select all

msecs.l = GetTickCount_() ; Win OS only
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by ricardo.
'_'-suffixed functions (kind of low-level ?? )
Windows API

http://www.allapi.net

Best Regards

Ricardo

Dont cry for me Argentina...
Post Reply