mirror of
https://github.com/xtrll/MusicMetaFinder.git
synced 2026-04-18 00:03:28 +02:00
feat: add cleanup function to delete images directory after execution
This commit is contained in:
24
src/utils/deleteDirectoryRecursively.js
Normal file
24
src/utils/deleteDirectoryRecursively.js
Normal file
@@ -0,0 +1,24 @@
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user