Re: File test [message #4430] |
Wed, 31 May 1995 00:00 |
knipp
Messages: 68 Registered: January 1993
|
Member |
|
|
In article acg@post.gsfc.nasa.gov, thompson@orpheus.nascom.nasa.gov (William Thompson) writes:
... (deleted)
>
> Actually, that's why I use. I find it extremely fast, much faster than the IDL
^
CORRECT ----------------------------------------------|
> built-in function called FINDFILE. I would, however, suggest modifying your
> routine to read
>
> FUNCTION fexists, file
> ON_IOERROR, error
> openr,unit,file
> free_lun,unit
> ; found the file
> return, 1
>
> error:
> ;can't open the file, so it's probably not there
> return,0
> end
>
> So that you don't run into a problem if unit 1 is already used elsewhere.
>
> Bill Thompson
I have a function EXIST_F (to check the existence of a file) using FINDFILE,
- and just yesterday I suggested to use FINDFILE for this.
Now , thanks to Bill Thompson, I realize that OPENR is much, much faster
- and find a function (I wrote some time ago) EXIST_D, which checks the
existence of a directory, ...
AND IT USES OPENR to perform that check.
So, next time be careful with my suggestions, ;-)
I must be out of my brain sometimes.
(A small difference to the above stated solution:
openr, unit, file, /get_lun, ERROR=ERROR
if ERROR ne 0 then return, 0
free_lun, unit
return, 1
)
By the way, the function EXIST_F now utilizes OPENR,... ;-)
Thanks again Bill
Karl
------------------------------------------------------------ ------------
Karlheinz Knipp
knipp@ipi.uni-hannover.de
------------------------------------------------------------ ------------
|
|
|
Re: File test [message #4432 is a reply to message #4430] |
Wed, 31 May 1995 00:00  |
sjt
Messages: 72 Registered: November 1993
|
Member |
|
|
William Thompson (thompson@orpheus.nascom.nasa.gov) wrote:
[ Original specification deleted]
: Actually, that's why I use. I find it extremely fast, much faster than the IDL
: built-in function called FINDFILE. I would, however, suggest modifying your
: routine to read
: FUNCTION fexists, file
: ON_IOERROR, error
: openr,unit,file
this should be
openr, unit, file, /get
otherwise you'll get an undefined variable error on the openr.
: free_lun,unit
: ; found the file
: return, 1
: error:
: ;can't open the file, so it's probably not there
: return,0
: end
: So that you don't run into a problem if unit 1 is already used elsewhere.
: Bill Thompson
--
+------------------------+---------------------------------- --+---------+
| James Tappin, | School of Physics & Space Research | O__ |
| sjt@star.sr.bham.ac.uk | University of Birmingham | -- \/` |
| Ph: 0121-414-6462. Fax: 0121-414-3722 | |
+----------------------------------------------------------- --+---------+
|
|
|
Re: File test [message #4444 is a reply to message #4430] |
Tue, 30 May 1995 00:00  |
hahn
Messages: 108 Registered: November 1993
|
Senior Member |
|
|
In article <1995May30.083524.18717@newsserver.rrzn.uni-hannover.de> knipp@ipi.uni-hannover.de (K Knipp) writes:
> found = findfile(FILENAME) ne "" ; FILENAME WITHOUT WILDCARD
> ; found will either be 0 or 1
Although this works I recommend to use findfile with the optional parameter
count and check this value: Findfile returns a string array with one element
per file or directory. So, if FILENAME is ambigous, you cannot compare it to
a null string.
BTW: If you enter wild card characters as argument the result returned depends
on the operating system. Using findfile in IDL for Windows the result is:
IDL> fl = findfile('d:\idl\*.*', count=nd)
IDL>print, nd
25
IDL> print, fl
d:\idl\.\
d:\idl\..\
d:\idl\HELP\
d:\idl\MAPS\
[ lines deleted]
d:\idl\EXPORT.H
d:\idl\DOSPRMPT.PIF
[remainder deleted]
While running under OSF/1 you get uxlis = findfile('$IDL_DIR/*', count=cn)
260 files and uxlis contains
/afs/software/idl/axp361/Idl
/afs/software/idl/axp361/README
/afs/software/idl/axp361/RELEASE_LEVEL
/afs/software/idl/axp361/colors1.tbl
/afs/software/idl/axp361/envi_setup
/afs/software/idl/axp361/envi_setup.ksh
[remainder deleted]
As you see all subdirectories are traversed, similar to the Unix find
command.
Norbert Hahn
|
|
|
Re: File test [message #4445 is a reply to message #4444] |
Tue, 30 May 1995 00:00  |
knipp
Messages: 68 Registered: January 1993
|
Member |
|
|
In article fsf@ruund7.fys.ruu.nl, wolf@ruund7.fys.ruu.nl (Wolf Wolfswinkel) writes:
> Hi,
>
> What is the best way to test for the existance of a file ? I can't
> find it in the manual. At the moment I use something like this :
>
> FUNCTION fexists, file
> ON_IOERROR, error
> openr,1,file
> close,1
> ; found the file
> return, 1
>
> error:
> ;can't open the file, so it's probably not there
> return,0
> end
>
> But there must be a much more elegant way, I think.
>
> Gr.
> Wolf
>
> --
> ===============================================
> \ /\ / Wolf Wolfswinkel
> \ / \ \/ /
> \/ \/\ /\ / W.Wolfswinkel@fys.ruu.nl
> \/ \/
>
found = findfile(FILENAME) ne "" ; FILENAME WITHOUT WILDCARD
; found will either be 0 or 1
Karl
------------------------------------------------------------ ------------
Karlheinz Knipp
knipp@ipi.uni-hannover.de
------------------------------------------------------------ ------------
|
|
|