-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcleanCache.js
32 lines (29 loc) · 891 Bytes
/
cleanCache.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
const fs = require('fs');
const path = require('path');
// Folder yang akan dibersihkan
const downloadFolder = path.join(__dirname, 'media/downloads');
// Fungsi untuk membersihkan folder
function cleanFolder(folderPath) {
fs.readdir(folderPath, (err, files) => {
if (err) {
console.error(`Error membaca folder ${folderPath}:`, err);
return;
}
files.forEach(file => {
const filePath = path.join(folderPath, file);
if (filePath) { // Tambahkan pengecekan ini
fs.unlink(filePath, err => {
if (err) {
console.error(`Error menghapus file ${filePath}:`, err);
} else {
console.log(`File ${filePath} berhasil dihapus`);
}
});
} else {
console.error(`File path tidak valid untuk file: ${file}`);
}
});
});
}
// Jalankan pembersihan
cleanFolder(downloadFolder);