Get folder/filename from a path

Get folder name, filename, file extension from a path:


# File name: Strip from start longest match of [*/]
FILENAME="${BASEFILE##*/}"
echo "FILENAME $FILENAME"

# Folder: Substring from 0 to start of filename
FOLDER="${BASEFILE:0:${#BASEFILE} - ${#FILENAME} - 1}"
echo "FOLDER $FOLDER"

# File prefix: Strip from end longest match of [dot plus at least one non-dot char]
FILEPREFIX="${FILENAME%.[^.]*}"
echo "FILEPREFIX $FILEPREFIX"

# File extension: Strip from start shortest match of [at least one non-dot char plus dot]
EXTENSION="${FILENAME##[^.]*.}"
echo "EXTENSION $EXTENSION"