-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3-paths.js
More file actions
25 lines (19 loc) · 1.15 KB
/
3-paths.js
File metadata and controls
25 lines (19 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// The diagram below shows the different names for parts of a file path on a Unix operating system
// ┌─────────────────────┬────────────┐
// │ dir │ base │
// ├──────┬ ├──────┬─────┤
// │ root │ │ name │ ext │
// " / home/user/dir / file .txt "
// └──────┴──────────────┴──────┴─────┘
// (All spaces in the "" line should be ignored. They are purely for formatting.)
const filePath = "/Users/mitch/cyf/Module-JS1/week-1/interpret/file.txt";
const lastSlashIndex = filePath.lastIndexOf("/");
const base = filePath.slice(lastSlashIndex + 1);
console.log(`The base part of ${filePath} is ${base}`);
// Create a variable to store the dir part of the filePath variable
// Create a variable to store the ext part of the variable
const dir =filePath.substring(1,lastSlashIndex) ;
const ext =filePath.substring(filePath.lastIndexOf(".")) ;
console.log(dir);
console.log(ext);
// https://www.google.com/search?q=slice+mdn