The file extension is typically everything after the last period. If a filename has no ".", it has no extension. What happens when the filename begins with a dot, as hidden files in linux do?
In python, the file has no extension...
>>> os.path.splitext("base.ext")
('base', '.ext')
>>> os.path.splitext(".ext")
('.ext', '')
The common method in bash produces the other result where there is only an extension and no base part (Extract filename and extension in Bash)...
>>> filename=".ext"
>>> extension="${filename##*.}"
>>> base="${filename%.*}"
>>> echo $base
>>> echo $extension
ext
How should code handle filenames such as this? Is there a standard? Does it differ per operating system? Or simply which is most common/consistent?
[EDIT]
Lets say you have a file that's just ".pdf
". Should, for example, an open dialogue default to listing it without 1. showing hidden files and 2. allowing all file extensions?
- It's a hidden file - it begins with a period
- Is it actually a .pdf (by filename convention, sure it has pdf data) or is it a file witn no extension?