使用cordova和apache/cordova-plugin-file插件,我怎樣才能得到一個給定目錄中超過30天的文件並刪除它們?Cordova檢索並刪除超過30天的文件?
0
A
回答
2
嘗試使用此代碼:
function daysDiff(now, fileDate) {
// thanks to http://stackoverflow.com/a/3224854/3340702
var timeDiff = Math.abs(now.getTime() - fileDate.getTime());
return Math.ceil(timeDiff/(1000 * 3600 * 24));
}
// Process file entries
function deleteOlderFiles(entries) {
var i;
var currentDate = new Date();
for (i=0; i<entries.length; i++) {
if(entries[i].isFile) {
entries[i].file(function(file) {
if(daysDiff(currentDate, file.lastModifiedDate) > 30) {
entries[i].remove(function(){
console.log("File removed");
}, function(){
console.log("Error while removing file");
});
}
}), error);
}
}
}
function fail(error) {
alert("Failed during operations: " + error.code);
}
// Get a directory reader
var directoryEntry = new DirectoryEntry(name, path);
var directoryReader = directoryEntry.createReader();
// Get a list of all the entries in the directory
directoryReader.readEntries(deleteOlderFiles, fail);
更多信息請參見DirectoryEntry,DirectoryReader和FileEntry文檔。
相關問題
- 1. 刪除超過30天的下載?
- 2. 的Unix刪除子文件夾在YYYYMMDD是超過30天
- 3. 用.bat刪除超過30天的文件fle
- 4. Solr4.1不能刪除超過30天的文檔
- 5. 刪除超過一天的文件
- 6. 需要刪除超過30天的文件夾,但排除一些
- 7. 在bash中查找超過X天的文件並刪除
- 8. 刪除與超過30%的缺失值
- 9. 刪除catalina。*。日誌超過30天使用logrotate
- 10. 刪除超過30天,如果不是一個月
- 11. 超過30天使用7zip
- 12. 檢查結果是否超過30天,並在
- 13. Cordova刪除文件
- 14. Bash(Linux)Shell腳本壓縮超過30天的文件
- 15. 刪除所有文件和目錄,超過5天的,除了一個文件
- 16. 在perl中刪除超過7天的文件
- 17. 在Jenkins工作區中刪除超過X天的文件
- 18. 用多個拉鍊刪除超過這麼多天的文件
- 19. 在Perl中刪除超過90天的文件
- 20. 使用PowerShell刪除超過15天的文件
- 21. 刪除所有超過5天的行
- 22. 檢查一個文件是否超過30天沒有find命令
- 23. 刪除30天以前的mysql記錄
- 24. 刪除文件夾及其內容年長超過2天PHP
- 25. 刪除文件夾和文件,如果文件夾的日期是30天
- 26. 找出日期是否超過30天
- 27. 根據非日期類型的字段刪除超過30天或更長時間的索引的策劃者
- 28. 如何檢查unix中的文件是否超過30分鐘
- 29. 刪除長達30天的文件,長路徑和長文件名
- 30. 上傳超過30個文件在PHP
看看這裏:http://docs.phonegap.com/en/edge/cordova_file_file.md.html你要找的是lastModifiedDate。 – Gusman