[Thread Prev][Thread Next][Index]

Re: [ferret_users] check if a particular file exists



Hello David,
              Please have a look at User Manual, Ch7 Sec2.11, SPAWN command.
Using spawn command, you can use a variable definition to know whether a 
file exists in cwd/pwd. See the example below.

Hope this helps,

Regards,

Jaison

!-------------example starts here------------------------------------------
\ cancel mode verify

    let fex = {spawn:"ls *.nc"}
    
    ! if file exists in pwd/cwd, the string variable fex will not be empty
    !    use this constrain to design a logical construct as follows
  
    IF `STRLEN(fex[i=1]) GT 0` THEN 
        say "  File exist in pwd/cwd."
    ELSE 
        say "  File DOES NOT exist in pwd/cwd."
    ENDIF
  
    ! Suppose you are using wild cards and want to know howmany files 
    !    (of a common type) exists in pwd/cwd, then : 
  
    let files  = XSEQUENCE(fex)
    let nfiles = `files,r=isize`
  
    say "  There are `nfiles` file/s of this type in pwd/cwd"
  
    ! Equally, you can use "nfiles" for checking the existance of a file
  
    IF `nfiles GT 0` THEN
        say "  This file exist in pwd/cwd."
    ELSE 
        say "  This file DOES NOT exist in pwd/cwd."
    ENDIF

!------example ends here---------------------------------------------------   


On Tue, 17 Apr 2007, David Wang wrote:

> Hello Ferreters,
> 
> I'd like to make a conditional construct so that if a particular netcdf file
> exists in the local directory, open it, if not, do something else. this is
> quite trivial in MATLAB using exist function, but seems nontrivial for me in
> FERRET. Does anyone have any ideas?
> 
> Thanks,
> David
> 
> 


[Thread Prev][Thread Next][Index]

Contact Us
Dept of Commerce / NOAA / OAR / PMEL / TMAP

Privacy Policy | Disclaimer | Accessibility Statement