-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtouch.js
More file actions
62 lines (45 loc) · 1.24 KB
/
touch.js
File metadata and controls
62 lines (45 loc) · 1.24 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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
var fs = require('fs');
const thingsToCreate = process.argv;
thingsToCreate.shift()
thingsToCreate.shift()
var directoryPath = thingsToCreate.pop();
function getDirPath(path ="") {
if(path === "..")
{
let arr =directoryPath.split("\\")
if(arr[arr.length -1].indexOf(".") > -1)
arr.pop();
arr.pop()
directoryPath = arr.join("\\")
return;
}
// if(path.indexOf(".") > -1)
// {
let arr =directoryPath.split("\\")
if(arr[arr.length -1].indexOf(".") > -1)
arr.pop();
directoryPath = arr.join("\\")
directoryPath= directoryPath + "\\" + path;;
return;
// }
}
function createFile(path){
// writeFile function with filename, content and callback function
if(fs.existsSync(path) === false)
fs.writeFileSync(path, '');
}
function createDir(path){
if(fs.existsSync(path) === false)
fs.mkdirSync(path);
}
for (const name of thingsToCreate) {
getDirPath(name);
if(name != ".."){
if(name.indexOf(".") > -1){
createFile(directoryPath)
}else{
createDir(directoryPath)
}
}
}
console.log("files created successfully...")