;+ ; NAME: ; isfile ; PURPOSE: ; Check if a file exists ; DESCRIPTION: ; CATEGORY: ; fileio ; CALLING SEQUENCE: ; exists = IsFile(fn) ; INPUTS: ; fn: the filename ; OPTIONAL INPUT PARAMETERS: ; KEYWORD INPUT PARAMETERS: ; OUTPUTS: ; exists (boolean): true if file exists ; KEYWORD OUTPUT PARAMETERS: ; COMMON BLOCKS: ; SIDE EFFECTS: ; RESTRICTIONS: ; PROCEDURE: ; call findfile ; MODIFICATION HISTORY: ; 2002/05/30 - Initial version written, Leslie Young SwRI ; 2011/10/20 - Protect against fn=' ' ;- function isfile, fn if n_elements(fn) eq 1 then begin res = findfile(fn, count = count) return, (count gt 0) and (strtrim(fn,2) ne '') endif else begin n = n_elements(fn) out = (strtrim(fn,2) ne '') ; to get the right size and protect against '' for i = 0, n-1 do out[i] = isfile(fn[i]) and out[i] return, out endelse end pro isfileTEST fn = 'isfile.pro' print, fn, IsFile(fn) fn = 'NoSuchFile' print, fn, IsFile(fn) end