Browse Source

Dateien hochladen nach „“

master
Jan Svabenik 4 years ago
parent
commit
270aebf08f
1 changed files with 39 additions and 0 deletions
  1. +39
    -0
      filecheck.js

+ 39
- 0
filecheck.js View File

@@ -0,0 +1,39 @@
//filechecker by Jan Svabenik
// *** ATTN: This code deletes files! ***

//requiring path and fs modules
const Fs = require('fs');
const path = require('path');
const actualdate = Date.now();
const ticksinday = 86000000;
const maxfileage = 10;
//joining path of directory

const directoryPath = path.join('./', '');


function createdDate(file) {
const {
birthtime
} = Fs.statSync(file)

return birthtime.getTime();
}

//passing directoryPath and callback function

Fs.readdir(directoryPath, function(err, files) {
//handling error
if (err) {
return console.log('Unable to scan directory: ' + err);
}
//listing all files using forEach
files.forEach(function(file) {
// Do whatever you want to do with the file
filedate = createdDate(directoryPath + '/' + file);
fileage = ((actualdate - filedate) / ticksinday).toFixed(0);
console.log(file + ' Age: ' + fileage + ' Days');
if (fileage > maxfileage) console.log(file + ' eligible for removal.');

});
});

Loading…
Cancel
Save