Liberty BASIC Help Online

Testing for File Existence
 
Here is a short user-defined function which can be used to test if a file exists on disk.  It is important to know if a file exists because attempting to access a nonexistent file can cause a program to crash.
 
function fileExists(path$, filename$)
  'dimension the array info$( at the beginning of your program
  files path$, filename$, info$()
  fileExists = val(info$(0, 0))  'non zero is true
end function
 
If the file is to be in the default directory, and named users.dat this example shows how to test for its existence with the fileExists function:
 
  dim info$(10, 10)
  if fileExists(DefaultDir$, "users.dat") then
    notice "It's alive!"
  else
    notice "Igor!  I need more power!"
  end if
 
The dim info$(10, 10) statement is important because the files command in the function needs to have a double dimensioned array ready to accept its list of files and their information.  See FILES.


Copyright (C) 2003 Shoptalk Systems
Liberty BASIC - http://www.libertybasic.com/