check existence of files in a folder

Hi I am having a problem to verify existence of files. I need to know whether or not files in a folder that begins with a name.
For example all files that start with The_File_ *.
I was doing it this way, but gives me error.

if text -f /work/The_File_*
then
...
else
..
fi

Isn't it:

if [ -f /work/The_File_* ]
then
     echo "Exists!"
fi

Or you can use, because the above can give you errors like: "too many arguments" when the shell expands "The_File_*":

numFiles=`find /work -name "The_File_*" | wc -l`
if [ ${numFiles} -gt 0 ]
then
     echo "Exists!"
fi

I put what you said and it shows me this error

./existe: line 3: [: too many arguments

That's what I said in my post! Try the "find" solution...

Work Work! Thanks!

is_file()
{
  for _file
  do
    [ -f "$_file" ] && return
  done
  return 1
}

if is_file /path/to/dir/The_File_*
then
  echo "File found"
else
  echo "No files"
fi

2 Likes