if [ -f "myFile.txt" ]; then
echo "File found"
fi
if ! [ -f "myFile.txt" ]; then
echo "File not found"
fi
// or as a bash function
openAnything() {
if [ -f "$@" ]; then // if file exist, open file...
code $@ // add your prefered editor/program
else
open $@ // if file not exist open as directory in finder
fi
}