mirror of
https://github.com/xtrll/MusicMetaFinder.git
synced 2026-04-17 15:53:29 +02:00
25 lines
629 B
JavaScript
25 lines
629 B
JavaScript
import { promises as fs } from 'fs';
|
|
import path from 'path';
|
|
|
|
/**
|
|
* Recursively deletes a directory and its contents.
|
|
* @param {string} dirPath - The path to the directory to delete.
|
|
*/
|
|
async function deleteDirectoryRecursively(dirPath) {
|
|
const entries = await fs.readdir(dirPath, { withFileTypes: true });
|
|
|
|
const promises = entries.map((entry) => {
|
|
const fullPath = path.join(dirPath, entry.name);
|
|
|
|
return entry.isDirectory()
|
|
? deleteDirectoryRecursively(fullPath)
|
|
: fs.unlink(fullPath);
|
|
});
|
|
|
|
await Promise.all(promises);
|
|
await fs.rmdir(dirPath);
|
|
}
|
|
|
|
export default deleteDirectoryRecursively;
|
|
|