如何获取文件系统中的最后修改日期和时间? [英] How to get last modified date and time in Filesystem?
问题描述
我正在尝试获取文件的上次修改日期和时间,该文件存储在我的本地设备内存目录中.是否可以在文件系统中获取lastmodifieddate?
Hi I am trying to get last modified date and time of file, which is stored in my local device memory directory. Is is possible to get lastmodifieddate in filesystem?
到目前为止,我一直在尝试以下代码
Till now i have been trying with the below code
function checkLastModifiedDate(){
window.resolveLocalFileSystemURL(cordova.file.
externalRootDirectory
+"Download/SMU/File Repo/SMUDE_Connect_User_Guide.pdf",
function(fs) {
LastModifiedDateOfFile(fs);
}, failFiles);
function failFiles(error) {
if (error.code == FileError.NOT_FOUND_ERR)
toastr.error('User guide manual not exists.', 'Information')
else if (error.code == FileError.SECURITY_ERR)
console.log("Message : SECURITY_ERR")
else if (error.code == FileError.ABORT_ERR)
console.log("Message : ABORT_ERR")
else if (error.code == FileError.NOT_READABLE_ERR)
console.log("Message : NOT_READABLE_ERR")
else if (error.code == FileError.ENCODING_ERR)
console.log("Message : ENCODING_ERR")
else if (error.code == FileError.NO_MODIFICATION_ALLOWED_ERR)
console.log("Message : NO_MODIFICATION_ALLOWED_ERR")
else if (error.code == FileError.INVALID_STATE_ERR)
console.log("Message : INVALID_STATE_ERR")
else if (error.code == FileError.SYNTAX_ERR)
console.log("Message : SYNTAX_ERR")
else if (error.code == FileError.INVALID_MODIFICATION_ERR)
console.log("Message : INVALID_MODIFICATION_ERR")
else if (error.code == FileError.QUOTA_EXCEEDED_ERR)
console.log("Message : QUOTA_EXCEEDED_ERR")
else if (error.code == FileError.PATH_EXISTS_ERR)
console.log("Message : PATH_EXISTS_ERR")
}
}
function LastModifiedDateOfFile(fileEntry){
var lastMod = fileEntry.lastModifiedDate;
//alert("lastMod - "+lastMod);
//var date = new Date(fileEntry.lastModified);
//alert("date - "+date);
}
引荐链接 http://www.html5rocks.com/en/tutorials/file/filesystem/
这样我们就可以做到,但是我不能通过输入标签选择文件
and this way we can do but im not choosing files through input tag http://jsbin.com/ajepef/1/edit?html,output
每次都显示未定义",我不确定lastmodifeddate属性是否存在. 如果有人知道,请帮助我.
Everytime is showing 'undefined', I am not sure lastmodifeddate attribute is there or not. If anybody know please help me.
推荐答案
尝试一下:
window.resolveLocalFileSystemURL(cordova.file.applicationDirectory + "YOUR_FILE_NAME", gotFile, fail);
function fail(e) {
console.log("FileSystem Error");
console.dir(e);
}
function gotFile(fileEntry) {
fileEntry.file(function(file) {
console.log(file.lastModifiedDate);
});
}
希望这会有所帮助
这篇关于如何获取文件系统中的最后修改日期和时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!