pathBaseName function
Returns the final segment of path (the file or last directory name).
Both / and \ are accepted as separators. A path with no separator is
returned unchanged.
Example:
pathBaseName('/usr/local/bin/dart'); // 'dart'
pathBaseName(r'C:\temp\file.txt'); // 'file.txt'
Implementation
String pathBaseName(String path) {
final String p = path.replaceAll(r'\', '/');
final int i = p.lastIndexOf('/');
return i == -1 ? p : p.replaceRange(0, i + 1, '');
}