chk_file_time.js 965 B

1234567891011121314151617181920212223242526272829
  1. /**
  2. * Created by Tony on 2018/7/25.
  3. */
  4. let fs = require('fs');
  5. // let files = [];
  6. let path = "D:/GitHome/ConstructionCost/tmp";
  7. fs.exists(path, function (exists) {
  8. if (exists) {
  9. fs.readdir(path, function (err, files) {
  10. let currentTime = (new Date()).valueOf();
  11. let timeGap = currentTime - (1000 * 60 * 60 * 24 * 0.5);
  12. files.forEach(function(file,index){
  13. if (file.indexOf(".xlsx") === (file.length - 5) ||
  14. file.indexOf(".pdf") === (file.length - 4)) {
  15. let curPath = path + "/" + file;
  16. fs.stat(curPath,function(err,data){
  17. //修改时间
  18. if (timeGap > data.mtime) {
  19. console.log(curPath + " will be deleted!");
  20. // fs.unlink(curPath);
  21. }
  22. });
  23. }
  24. });
  25. })
  26. }
  27. })