getFilePathLevel function
Determine how many steps the current path is. The root path (/ or C:\) begins with step 1.
Implementation
int getFilePathLevel(String? filePath) {
if (filePath == null || filePath.isEmpty) {
return -1;
}
if (filePath == '/') {
return 1;
}
// Strip trailing separators of either flavour so that '/home/user' and
// '/home/user/' report the same level.
return toPosixFilePath(filePath.replaceAll(RegExp(r'[\\/]+$'), ''))
.split(posix.separator)
.length;
}