mirror of
https://github.com/kmvan/x-prober.git
synced 2026-04-21 16:59:02 +08:00
28 lines
496 B
JavaScript
28 lines
496 B
JavaScript
import {
|
|
existsSync,
|
|
readdirSync,
|
|
rmdirSync,
|
|
statSync,
|
|
unlinkSync,
|
|
} from 'node:fs';
|
|
import path from 'node:path';
|
|
/**
|
|
* Remove files
|
|
* @param {string} dir
|
|
*/
|
|
export const rmFiles = (dir) => {
|
|
if (!existsSync(dir)) {
|
|
return;
|
|
}
|
|
const files = readdirSync(dir);
|
|
for (const file of files) {
|
|
const filePath = path.join(dir, file);
|
|
if (statSync(filePath).isDirectory()) {
|
|
rmFiles(filePath);
|
|
} else {
|
|
unlinkSync(filePath);
|
|
}
|
|
}
|
|
rmdirSync(dir);
|
|
};
|