INNER CODE UNIT · JavaScript

deleteDirectory

ozgrozer/ai-renamer · src/deleteDirectory.js:4

const deleteDirectory = ({ folderPath }) => {
  if (fs.existsSync(folderPath)) {
    fs.readdirSync(folderPath).forEach((file) => {
      const curPath = path.join(folderPath, file)
      if (fs.lstatSync(curPath).isDirectory()) {
        deleteDirectory({ folderPath: curPath })
      } else {
        fs.unlinkSync(curPath)
      }
    })
    fs.rmdirSync(folderPath)
  }
}

module.exports = deleteDirectory

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…