Skip to content

Commit b574e15

Browse files
committed
fix logic for selecting dir part
1 parent 5480a21 commit b574e15

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed
Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
// The diagram below shows the different names for parts of a file path on a Unix operating system
22

33
// ????????????????????????????????????
4-
// ? dir ? base ?
5-
// ???????? ??????????????
6-
// ? root ? ? name ? ext ?
4+
// ┌─────────────────────┬────────────┐
5+
// │ dir │ base │
6+
// ├──────┬ ├──────┬─────┤
7+
// │ root │ │ name │ ext │
78
// " / home/user/dir / file .txt "
8-
// ????????????????????????????????????
9+
// └──────┴──────────────┴──────┴─────┘
910

1011
// (All spaces in the "" line should be ignored. They are purely for formatting.)
1112

@@ -17,7 +18,9 @@ console.log(`The base part of ${filePath} is ${base}`);
1718
// Create a variable to store the dir part of the filePath variable
1819
// Create a variable to store the ext part of the variable
1920

20-
const dir = filePath.slice(filePath.indexOf("/") + 1, lastSlashIndex);
21+
const dir = filePath.slice(filePath.indexOf("/"), lastSlashIndex);
2122
const ext = base.slice(base.lastIndexOf("."));
2223

24+
console.log(dir);
25+
2326
// https://www.google.com/search?q=slice+mdn

0 commit comments

Comments
 (0)