Files
archived-x-prober/tools/rm-files.mjs
2022-04-28 14:35:59 +08:00

22 lines
466 B
JavaScript

import { existsSync, readdirSync, rmdirSync, statSync, unlinkSync } from 'fs'
import path from '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)
}