pathWithoutExtension function
Returns path with its trailing file extension (and the dot) removed.
A leading dot (dotfile like .gitignore) is not treated as an extension,
so such paths are returned unchanged.
Example:
pathWithoutExtension('archive.tar.gz'); // 'archive.tar'
pathWithoutExtension('.gitignore'); // '.gitignore'
Implementation
String pathWithoutExtension(String path) {
final int dotIndex = path.lastIndexOf('.');
if (dotIndex <= 0) return path;
final String copy = path;
return copy.replaceRange(dotIndex, path.length, '');
}