walkToRootUntilFound function
Walks upward from folder until filename is found.
Returns null when no matching file exists up to the filesystem root.
Implementation
File? walkToRootUntilFound(String folder, String filename) {
final Directory current = Directory(folder).absolute;
final File candidate = File(
'${current.path}${Platform.pathSeparator}$filename',
);
if (candidate.existsSync()) {
return candidate;
}
final Directory parent = current.parent.absolute;
if (parent.path == current.path) {
return null;
}
return walkToRootUntilFound(parent.path, filename);
}