-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathscript-deleteall.js
More file actions
25 lines (22 loc) · 836 Bytes
/
Copy pathscript-deleteall.js
File metadata and controls
25 lines (22 loc) · 836 Bytes
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
const connectDB = require('./config/database');
const File = require('./models/file');
const path = require('path');
const fs = require('fs');
connectDB();
async function deleteData() {
const allFiles = await File.find();
if (allFiles.length) {
for (const removeFile of allFiles) {
try {
fs.unlinkSync(path.join(__dirname, removeFile.filePath));
await removeFile.remove();
console.log(`File Deleted ${removeFile.fileName} ${removeFile.filePath}`);
} catch(error) {
console.log(`Error Occured ${removeFile.fileName} ${path.join(__dirname, removeFile.filePath)}`);
console.log(error);
}
}
}
console.log("Operation Completed");
}
deleteData().then(process.exit);