/**
 * Created by Tony on 2018/7/25.
 */

let fs = require('fs');

// let files = [];
let path = "D:/GitHome/ConstructionCost/tmp";
fs.exists(path, function (exists) {
    if (exists) {
        fs.readdir(path, function (err, files) {
            let currentTime = (new Date()).valueOf();
            let timeGap = currentTime - (1000 * 60 * 60 * 24 * 0.5);
            files.forEach(function(file,index){
                if (file.indexOf(".xlsx") === (file.length - 5) ||
                    file.indexOf(".pdf") === (file.length - 4)) {
                    let curPath = path + "/" + file;
                    fs.stat(curPath,function(err,data){
                        //修改时间
                        if (timeGap > data.mtime) {
                            console.log(curPath + " will be deleted!");
                            // fs.unlink(curPath);
                        }
                    });
                }
            });
        })
    }
})