ConceptCreator/app/storage/FileUtils.js
Sebastian Böckelmann 0884709603
All checks were successful
E2E Testing / test (push) Successful in 1m41s
Persist Characters
2024-03-22 10:01:47 +01:00

39 lines
1.2 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.FileUtils = void 0;
const fs = require("fs");
const path = require("node:path");
const fs_1 = require("fs");
class FileUtils {
static listFilesInDirectory(directory) {
if (fs.lstatSync(directory).isDirectory()) {
return fs.readdirSync(directory).map(fileName => path.join(directory, fileName));
}
else {
return [];
}
}
static prepareFileForWriting(file) {
const parentDirectory = path.dirname(file);
if (!fs.existsSync(parentDirectory)) {
(0, fs_1.mkdirSync)(parentDirectory, { recursive: true });
}
}
static prepareDirectoryFroWriting(directoryFile) {
if (!fs.existsSync(directoryFile)) {
(0, fs_1.mkdirSync)(directoryFile, { recursive: true });
}
}
static removeFiles(files) {
files.forEach(file => {
if (fs.lstatSync(file).isDirectory()) {
fs.rmdirSync(file);
}
else {
fs.unlinkSync(file);
}
});
}
}
exports.FileUtils = FileUtils;
//# sourceMappingURL=FileUtils.js.map