pathtail function
Get the last n segment of a path.
var path = '~/Downloads/ft/README.md';
print(pathtail(path, 0)); // ''; empty string
print(pathtail(path, 1)); // 'README.md'; last
print(pathtail(path, 2)); // 'ft/README.md'
print(pathtail(path, 3)); // 'Downloads/ft/README.md'
print(pathtail(path, 4)); // '~/Downloads/ft/README.md'
print(pathtail(path, 5)); // '~/Downloads/ft/README.md'
Implementation
String pathtail(String path, int n) =>
(n <= 0 || path.isEmpty) ? '' : p.joinAll(tails(p.split(path), n));