[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: filename check

In article
<Pine.OSF.3.96.1001024143333.20360F-100000@zuaxp7.star.ucl.ac.uk>, Stuart
Colley <src@star.ucl.ac.uk> wrote:

>Can anyone suggest a way to check that a file exists before attempting to
>read from it, since the error messages obtained from trying to read from a
>non-existing file, don't make it clear that file doesn't exist.

;; The following requires IDL 5.3 or higher...
;; if you don't have it, you'll have to figure
;; out the type yourself using the normal size
;; function
function file_exists, fileName

  if( size( fileName, /type ) ne 7 ) then return, 0

  fileList = findfile( fileName )
  if( fileList[0] eq '' ) then return, 0 else return, 1

end ;; file_exists


Good luck!