A simple solution without external commands.

# BASH
# What is this directory?

fname='txtfile'
echo $(dirname "$fname")                # output: .
echo $(readlink -f "$fname")            # output: /home/me/work/txtfile

echo $(dirname $(readlink -f "$fname")) # output: /home/me/work

(From this Stackoverflow answer)