Unsatisfactory 'file_test()' behavior [message #28435] |
Mon, 17 December 2001 06:43  |
mfein
Messages: 2 Registered: November 2001
|
Junior Member |
|
|
Hi all--
If I do
e = file_test('')
that is, test for the existence of a file whose name is a zero-length
string, I get e = 1. This is not good ! (Using IDL v5.4 WinNT 4.0).
Matt Feinstein does not include his email address
in the text of usenet postings.
--------
Harvard Law of Automotive Repair: Anything that goes away
by itself will come back by itself.
|
|
|
Re: Unsatisfactory 'file_test()' behavior [message #28585 is a reply to message #28435] |
Thu, 20 December 2001 10:43  |
Liam E. Gumley
Messages: 378 Registered: January 2000
|
Senior Member |
|
|
Matt Feinstein wrote:
> If I do
>
> e = file_test('')
>
> that is, test for the existence of a file whose name is a zero-length
> string, I get e = 1. This is not good ! (Using IDL v5.4 WinNT 4.0).
How about this:
FUNCTION FILETEST, FILE, VERBOSE=VERBOSE
;- Returns true (1B) if the named file can be
;- opened for reading, and false (0B) otherwise
;- Try opening the file for reading
openr, lun, file, /get_lun, error=error
;- Check error status
if (error eq 0) then begin
result = 1B
free_lun, lun
endif else begin
result = 0B
if keyword_set(verbose) then $
message, !err_string, /continue
endelse
;- Return result
return, result
END
IDL> help, filetest('')
<Expression> BYTE = 0
IDL> help, filetest('', /verbose)
% FILETEST: OPENR: Null filename not allowed.
<Expression> BYTE = 0
Cheers,
Liam.
Practical IDL Programming
http://www.gumley.com/
|
|
|