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

时间:2021-11-27 10:19:27

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?

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

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

referred links http://www.html5rocks.com/en/tutorials/file/filesystem/

推荐链接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

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

Everytime is showing 'undefined', I am not sure lastmodifeddate attribute is there or not. If anybody know please help me.

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

2 个解决方案

#1


0  

Try this out:

试试这个:

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

Hope this helps

希望这可以帮助

#2


0  

You have to use file method of file entry.Change your LastModifiedDateOfFile function as followings:

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

    function LastModifiedDateOfFile(fileEntry){
    fileEntry.file(successFile,errorFile);

    function successFile(entry){
        alert(entry.lastModified);
    }
    function errorFile(error){
        alert("error");
    }
}

#1


0  

Try this out:

试试这个:

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

Hope this helps

希望这可以帮助

#2


0  

You have to use file method of file entry.Change your LastModifiedDateOfFile function as followings:

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

    function LastModifiedDateOfFile(fileEntry){
    fileEntry.file(successFile,errorFile);

    function successFile(entry){
        alert(entry.lastModified);
    }
    function errorFile(error){
        alert("error");
    }
}