forked from CodeYourFuture/Module-JS1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpaths.js
More file actions
18 lines (14 loc) Β· 985 Bytes
/
paths.js
File metadata and controls
18 lines (14 loc) Β· 985 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// 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