Fix file name sanitization.

This better handles file names with dots in the path
and no file extension.

Fixes #344.