-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.js
45 lines (38 loc) · 1.06 KB
/
util.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
42
43
44
45
/*
search for .tray inside of a list of files
*/
var fs = require('fs');
var path = require('path');
var docPath = require('./config.js').docPath;
module.exports.searchForTray = () => {
var exists = fs.existsSync(`${docPath}`);
return exists;
}
module.exports.testTrayAsDir = () => {
var stats = fs.statSync(`${docPath}`);
return stats.isDirectory();
}
module.exports.testFileExists = async (path) => {
try {
if (fs.existsSync(path)) {
//file exists
return true;
}
} catch(err) {
console.error(err)
return false;
}
}
const deleteFolderRecursive = async (directory_path) => {
if (fs.existsSync(directory_path)) {
fs.readdirSync(directory_path).forEach(function (file, index) {
var currentPath = path.join(directory_path, file);
if (fs.lstatSync(currentPath).isDirectory()) {
deleteFolderRecursive(currentPath);
} else {
fs.unlinkSync(currentPath); // delete file
}
});
}
};
module.exports.deleteFolderRecursive = deleteFolderRecursive;