1- // The diagram below shows the different names for parts of a file path on a Unix operating system
2-
3- // ┌─────────────────────┬────────────┐
4- // │ dir │ base │
5- // ├──────┬ ├──────┬─────┤
6- // │ root │ │ name │ ext │
7- // " / home/user/dir / file .txt "
8- // └──────┴──────────────┴──────┴─────┘
9-
10- // (All spaces in the "" line should be ignored. They are purely for formatting.)
11-
12- const filePath = "/Users/mitch/cyf/Module-JS1/week-1/interpret/file.txt" ;
13- const lastSlashIndex = filePath . lastIndexOf ( "/" ) ;
14- const base = filePath . slice ( lastSlashIndex + 1 ) ;
15- console . log ( `The base part of ${ filePath } is ${ base } ` ) ;
16-
17- // Create a variable to store the dir part of the filePath variable
18- // Create a variable to store the ext part of the variable
19-
20- const dir = ;
21- const ext = ;
22-
1+ // The diagram below shows the different names for parts of a file path on a Unix operating system
2+
3+ // ┌─────────────────────┬────────────┐
4+ // │ dir │ base │
5+ // ├──────┬ ├──────┬─────┤
6+ // │ root │ │ name │ ext │
7+ // " / home/user/dir / file .txt "
8+ // └──────┴──────────────┴──────┴─────┘
9+
10+ // (All spaces in the "" line should be ignored. They are purely for formatting.)
11+
12+ const filePath = "/Users/mitch/cyf/Module-JS1/week-1/interpret/file.txt" ;
13+ const lastSlashIndex = filePath . lastIndexOf ( "/" ) ;
14+ const base = filePath . slice ( lastSlashIndex + 1 ) ;
15+ console . log ( `The base part of ${ filePath } is ${ base } ` ) ;
16+
17+ // Create a variable to store the dir part of the filePath variable
18+ // Create a variable to store the ext part of the variable
19+
20+ const dir = filePath . slice ( 0 , lastSlashIndex ) ;
21+ const ext = filePath . slice ( filePath . lastIndexOf ( "." ) ) ;
22+
23+ console . log ( dir ) ;
24+ console . log ( ext ) ;
25+
2326// https://www.google.com/search?q=slice+mdn
0 commit comments