-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcleanup.js
More file actions
30 lines (24 loc) · 724 Bytes
/
Copy pathcleanup.js
File metadata and controls
30 lines (24 loc) · 724 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
26
27
28
29
30
const fs = require("fs");
const path = require("path");
const OUTPUTS_DIRECTORY = path.join(__dirname, "./outputs");
const NOW = new Date();
dirItemsRemove(OUTPUTS_DIRECTORY);
function readdirSync(p, a = []) {
if (fs.statSync(p).isDirectory())
fs.readdirSync(p).map((f) =>
readdirSync(a[a.push(path.join(p, f)) - 1], a)
);
return a;
}
function dirItemsRemove(DIRECTORY_PATH) {
const files = readdirSync(DIRECTORY_PATH);
console.log(files);
files.map((file) => {
const stats = fs.statSync(file);
const createdAt = stats.ctime;
if (NOW.getTime() - createdAt.getTime() > 1 * 6 * 60 * 60 * 1000) {
// 6 hours
fs.rmSync(file, { recursive: true, force: true });
}
});
}