소스 검색

Dateien hochladen nach „“

master
Jan Svabenik 4 년 전
부모
커밋
270aebf08f
1개의 변경된 파일39개의 추가작업 그리고 0개의 파일을 삭제
  1. +39
    -0
      filecheck.js

+ 39
- 0
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.');

});
});

불러오는 중...
취소
저장