Access to local file change time in javascript

Is there a way to get the file modification time (either ctime or mtime should work) that is accessed locally via javascript.

I want to go to file: ///home/me/mtime.html and tell javascript that /home/me/file.txt was changed 2 minutes ago or something like that. I understand that javascript has limited access to files due to security issues, but is there any trick since it runs locally.

Thanks.

+5
source share
4 answers

Firefox has a set of components under its XPCOM (ActiveX competitor technology) that you can use to accomplish the same thing.

Maybe something like this (untested):

function getLastModifiedTime(filePath) 
{
    try 
    {
        netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
    } 
    catch (e) 
    {
        throw new Error("Permission to read file was denied.");
    }

    var file = Components.classes["@mozilla.org/file/local;1"]
    .createInstance(Components.interfaces.nsILocalFile);

    file.initWithPath( filePath );

    return file.lastModifiedTime;
}

Safari... . , java-?

+1

javascript ActiveX, , , :

<script language=jscript runat=server> 
    var thisfile = <File_Path>; 
    thisfile = Server.MapPath(thisfile); 
    var fso = new ActiveXObject("Scripting.FileSystemObject"); 
    var fs = fso.GetFile(thisfile); 
    var dlm = fs.DateLastModified; 
    Response.Write("Last modified: " + dlm); 
</script>

, , javascript dlm .

+1

Perhaps through ActiveX or some other browser component that allows the user to provide advanced browser permissions, such as HTA or through something like Google Gears.

In other words, "No" if you do not want to do something non-standard.

0
source

Sorry, but this is not possible with JavaScript.

0
source

All Articles