From 270aebf08fa0ca8dc895bd0220a0c3b0b7d5c25d Mon Sep 17 00:00:00 2001 From: Jan Svabenik Date: Mon, 12 Apr 2021 05:29:29 +0000 Subject: [PATCH] =?UTF-8?q?Dateien=20hochladen=20nach=20=E2=80=9E=E2=80=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- filecheck.js | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 filecheck.js diff --git a/filecheck.js b/filecheck.js new file mode 100644 index 0000000..8bd02d4 --- /dev/null +++ b/filecheck.js @@ -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.'); + + }); +}); \ No newline at end of file