ConceptCreator/app/storage/FileUtils.ts
Sebastian Böckelmann e6073d4f2f
Some checks failed
E2E Testing / test (push) Failing after 1m41s
Save Gamesystems
2024-03-20 19:35:24 +01:00

23 lines
560 B
TypeScript

import * as fs from "fs";
import * as path from "node:path";
import {mkdirSync} from "fs";
export class FileUtils {
public static listFilesInDirectory(directory: string) {
if(fs.lstatSync(directory).isDirectory()) {
return fs.readdirSync(directory).map(fileName => path.join(directory, fileName))
} else {
return [];
}
}
public static prepareFileForWriting(file: string) {
const parentDirectory = path.dirname(file)
if(!fs.existsSync(parentDirectory)) {
mkdirSync(parentDirectory, {recursive: true})
}
}
}