Auto generating folders, more compatibility running on any machine

This commit is contained in:
YourFriendlyNeighborhoodDealer 2018-12-21 13:00:05 +01:00
parent c10a5a8a6c
commit 7edce016b5
5 changed files with 90 additions and 71 deletions

View file

@ -4,7 +4,9 @@ module.exports = {
writeFileAsync: WriteFileAsync,
AppendToFile: AppendToFile,
Beep: Beep,
WriteBackup: WriteBackup
WriteBackup: WriteBackup,
FileExists: FileExists,
CreatePath: CreatePath
};
var fs = require('fs');
@ -18,25 +20,32 @@ const manFile = "public/man.html";
const logFile = "stats/logs";
function ReadFile(name) {
if (!fs.existsSync(name))
if (!FileExists(name))
throw "No such file: " + name;
return fs.readFileSync(name, "utf8");
}
function CreatePath(path) {
if (fs.existsSync(path))
function FileExists(path) {
return fs.existsSync(path);
}
function CreatePath(path, onlyPath) {
if (FileExists(path))
return;
var p = path.split("/");
var currDir = p[0];
for (var i = 1; i < p.length; i++) {
console.log(currDir);
if (!fs.existsSync(currDir)) {
fs.mkdirSync(currDir);
}
currDir += "/" + p[i];
}
fs.writeFileSync(path, "");
if (onlyPath == undefined || onlyPath == false)
fs.writeFileSync(path, "");
else
fs.mkdirSync(path);
}
function WriteFile(content, path) {