23 lines
560 B
TypeScript
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})
|
|
}
|
|
}
|
|
}
|