mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
Auto generating folders, more compatibility running on any machine
This commit is contained in:
parent
c10a5a8a6c
commit
7edce016b5
5 changed files with 90 additions and 71 deletions
21
utils.js
21
utils.js
|
@ -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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue