-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathb.js
41 lines (34 loc) · 1005 Bytes
/
b.js
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
const path = require("path");
const basePath = "/a/b/c";
const basePath2 = "/a/b/c/";
const absolutePath = "/a/b/c/d/y.js";
const relationPath = "../c/d/y.js";
function toRelationPath(basePath, absolutePath) {
return path.join(
"..",
path.basename(basePath),
path.relative(basePath, absolutePath)
);
}
function toAbsolutePath(basePath, relationPath) {
return path.join(basePath, relationPath);
}
console.log(absolutePath === toAbsolutePath(basePath, relationPath));
console.log(absolutePath === toAbsolutePath(basePath2, relationPath));
console.log(relationPath === toRelationPath(basePath, absolutePath));
console.log(relationPath === toRelationPath(basePath2, absolutePath));
const root = {
path: "..",
name: path.basename(basePath),
};
const Desktop = {
path: path.join(root.path, root.name),
name: "Desktop",
children: [],
};
Desktop.children.push({
path: path.join(Desktop.path, Desktop.name),
name: "文件夹",
children: [],
});
console.log(root, Desktop);