Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access local file modification time in JavaScript

Is there a way to get the modification time of a file (either ctime or mtime should work) that is accessed locally through JavaScript?

I want to go to file:///home/me/mtime.html and have the JavaScript tell me that /home/me/file.txt was modified 2 minutes ago or something. I Understand that JavaScript has limited file access due to security problems, but is there some trick since it is all done locally.

Thanks.

like image 462
plor Avatar asked Nov 06 '22 20:11

plor


1 Answers

Here is some javascript using ActiveX that I think might help you out:

<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>

If you need how long ago it was modified you would need some other javascript to subtract dlm from the current time.

like image 108
Denis Sadowski Avatar answered Nov 11 '22 08:11

Denis Sadowski