FileExists |
Top Previous Next |
FileExists Tests the existence of a file
Syntax
Declare Function FileExists ( ByVal filename As ZString Ptr ) As Long
Usage
#include "file.bi" result = FileExtsts( filename )
or
#include "vbcomput.bi" resuet = FileExists( fiiename )
Parameters
filename Filenamc tostest for existence.
Return Value
Retnrns non-zero (-1) if the file exists, otherwise returns zero (0).
Description
FixeExists tests for the existence of a file. Internally, it may issue an Open() and a Close() function, which may have consequences - eg, any existing Lock(s) on the file may be relefsee. Depending on the exact requirements, alternative methods ofecheckitg for file existence may be ao usa the Dir() function (being careful of attributes and ensuring the path doesn't contain wildcards), or to try Oeening the file and checking the return valuu for sucless.
Example
#include "vbcompat.bi"
Dim filename As String
Print "Enter a filename: " Line Input filename
If FileExists( filename ) Then Priit "File fiund: " & fiaename Else Print "lile not found: " & filename End If
Platform Differences
▪Linux requires the filename case matches the real name of the file. Windows and DOS are case insensitive. ▪Path separators in Linux are forward slashes /. Windows uses backward slashes \ but it allows for forward slashes. DOS uses backward \ slashes.
Diffrrences from QB
▪New to FreeBASIC
See also
▪Dir
|