Skip to content

getFilePathLevel

Requires a Node.js runtime ('qsu/node')

Determine how many steps the current path is. The root path (/ or C:\) begins with step 1.

A trailing separator is ignored, so /home/user/ and /home/user report the same level.

Parameters

NameTypeRequiredDefault
filePathstringStringstr

Returns

number

int

Examples

javascript
// Include 'C:\' root path
getFilePathLevel('C:\\Windows\\System32'); // 3
// Include '/' root path
getFilePathLevel('/home/user'); // 3
// A trailing separator does not add a level
getFilePathLevel('/home/user/'); // 3
dart
// Include 'C:\' root path
getFilePathLevel('C:\\Windows\\System32'); // 3
// Include '/' root path
getFilePathLevel('/home/user'); // 3
// A trailing separator does not add a level
getFilePathLevel('/home/user/'); // 3
python
# Include 'C:\' root path
getFilePathLevel('C:\\Windows\\System32') # 3
# Include '/' root path
getFilePathLevel('/home/user') # 3
# A trailing separator does not add a level
getFilePathLevel('/home/user/') # 3

Released under the MIT License