Find Existence of File with wild card using Csh

Hi All,

I would like to find out the existence of files with wild card using CSH.
I have used the below code but does not seem to work.
Can any expert give me some advice ?

set nonomatch
set pattern = "_xxx"
set filetype =  ( *$pattern* ) 

if ( -e $filetype) then  
        echo "FILES with $pattern EXISTS"
else
        echo "FILES with $pattern DOES NOT EXISTS"
endif

The problem is that the -e test expects just one file name, so it breaks if your pattern matches several files. Do the test on just one file, i.e. the first element of $filetype:

if ( -e $filetype[1] ) then
        echo "FILES with $pattern EXISTS"
else
        echo "FILES with $pattern DOES NOT EXISTS"
endif

Hi spirtle,

Thanks alot for the advice.
It's working fine now. :slight_smile: