If file pattern exists in directory then continue

he below looks in $dir for any pattern of fileone . As is, it executes but only returns File found if the exact format in the script exsists. Why isn't a pattern of fileone being looked for and if it is in

$dir, File found. I think that is what should happen. Thank you :).



dir=/path/to
if ls "$dir"/fileone.csv* > /dev/null 2>&1
then
    echo "File not found!" >> "$dir"/log && exit 0
else
    echo "File was found, moving on " >> "$dir"/log
fi

Don't understand. Above will echo "File not found!" if any file name beginning with fileone.csv exists in dir , like

fileone.csv
fileone.csv12
fileone.csvacbdefaj
fileone.csv_sdfwegf

If none of those or alike exist, it will echo "File was found, moving on ".

1 Like

If any of the below are in $dir then File found was found, moving on.

fileone.csv
fileOne.csv
Fileone.csv
FileOne.csv

If none of those or alike exist, it will echo "File was found and exit. The pattern will always be fileone.csv just the case may be different. Maybe there is a better way? Thank you :).

Please take care when formulating your request. Misleading specifications may lead to unsatisfactory proposals.

Try

if ls "$dir"/[Ff]ile[Oo]ne.csv > /dev/null 2>&1
  then  echo "File was found, moving on "
  else  echo "File not found!"
fi
1 Like

Define a file_exists function.
Then you can do

if file_exists "$dir"/[Ff]ile[Oo]ne.csv
then
...
1 Like

Thank you both :).