如何在Filesystem中获取最后修改日期和时间?

时间:2016-05-26 05:45:11

标签: javascript html5 cordova filesystems

您好我正在尝试获取文件的最后修改日期和时间,该文件存储在我的本地设备内存目录中。是否可以在文件系统中获得lastmodifieddate?

直到现在我一直在尝试使用以下代码

 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/

这样我们可以做但不是通过输入标签选择文件 http://jsbin.com/ajepef/1/edit?html,output

每次都显示'undefined',我不确定lastmodifeddate属性是否存在。 如果有人知道请帮助我。

2 个答案:

答案 0 :(得分:0)

你必须使用文件输入的文件方法。更改你的LastModifiedDateOfFile函数如下:

str1 <- c("Ryerson, Master. John Borie", 
       "Corey, Mrs. Percy C (Mary Phyllis Elizabeth Miller)")

答案 1 :(得分:0)

试试这个:

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);        
    });
}

希望这有帮助

相关问题