ConceptCreator/app/storage/FileUtils.js

34 lines
1019 B
JavaScript
Raw Normal View History

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.FileUtils = void 0;
const fs = require("fs");
const path = require("node:path");
2024-03-20 19:35:24 +01:00
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 [];
}
}
2024-03-20 19:35:24 +01:00
static prepareFileForWriting(file) {
const parentDirectory = path.dirname(file);
if (!fs.existsSync(parentDirectory)) {
(0, fs_1.mkdirSync)(parentDirectory, { recursive: true });
}
}
2024-03-21 08:43:28 +01:00
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