Spaces:
Paused
Paused
File size: 449 Bytes
5b3c62d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
import { existsSync, promises as fs } from "node:fs"
export const deleteFileIfExists = async (filePath: string) => {
// this function scares me a bit,
if (filePath === "/" || filePath === "~" || filePath === ".") {
throw new Error(`lol, no.`)
}
if (existsSync(filePath)) {
try {
await fs.unlink(filePath)
return true
} catch (err) {
console.log(`failed to delete file ${filePath}`)
}
}
return false
} |