mirror of
https://github.com/kmvan/x-prober.git
synced 2026-04-22 01:08:59 +08:00
22 lines
466 B
JavaScript
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)
|
|
}
|