progress
This commit is contained in:
parent
6f86377685
commit
8ecb036b1d
36 changed files with 498 additions and 212 deletions
29
server/src/core/repository/fs.ts
Normal file
29
server/src/core/repository/fs.ts
Normal file
|
@ -0,0 +1,29 @@
|
|||
import * as fs from "fs";
|
||||
import { promisify } from "node:util";
|
||||
|
||||
export const readFileAsync = promisify(fs.readFile);
|
||||
export const readdir = promisify(fs.readdir);
|
||||
export const stat = promisify(fs.stat);
|
||||
export const lsStat = promisify(fs.lstat);
|
||||
export const createDir = promisify(fs.mkdir);
|
||||
export const dirIsExists = promisify(fs.exists);
|
||||
|
||||
export function readDirRecursive(path: string, filesToDir: string[] = []) {
|
||||
const files = fs.readdirSync(path);
|
||||
files.forEach((file) => {
|
||||
let filePath = "";
|
||||
if (path[path.length - 1] !== "/") {
|
||||
filePath = `${path}/${file}`;
|
||||
} else {
|
||||
filePath = `${path}${file}`;
|
||||
}
|
||||
|
||||
const stats = fs.statSync(filePath);
|
||||
if (stats.isDirectory()) {
|
||||
readDirRecursive(filePath, filesToDir);
|
||||
} else {
|
||||
filesToDir.push(file);
|
||||
}
|
||||
});
|
||||
return filesToDir;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue