获取文件创建、修改最后访问时间

.net 方法

private String filesize(String filename)
        {
            String _this = "";
            if (!String.IsNullOrEmpty(filename))
            {
                FileInfo objFI = new FileInfo(filename);
                _this += "详细路径:" + objFI.FullName;
                _this += "<br>文件名称:" + objFI.Name;
                _this += "<br>文件长度:" + objFI.Length.ToString();
                _this += "字节<br>创建时间" + objFI.CreationTime.ToString();
                _this += "<br>最后访问时间:" + objFI.LastAccessTime.ToString();
                _this += "<br>修改时间:" + objFI.LastWriteTime.ToString();
                _this += "<br>所在目录:" + objFI.DirectoryName;
                _this += "<br>扩展名:" + objFI.Extension;
                DateTime s1 = objFI.CreationTime;
                DateTime s2 = System.DateTime.Now;
                TimeSpan dt = s2 - s1;
                _this += "<br>创建时间距离现在分钟数:" + System.Convert.ToInt32(dt.TotalMinutes);
                _this += "<br>创建时间距离现在的小时个数:" + System.Convert.ToInt32(dt.TotalHours);
                _this += "<br>创建时间距离现在的天数:" + System.Convert.ToInt32(dt.TotalDays);
            }
            return _this;
        }

Js方法

 

function ShowFileAccessInfo(filespec) {
    var fso, f, s;
    fso = new ActiveXObject("Scripting.FileSystemObject");
   f = fso.GetFile(filespec); // filespec 是指定文件的路径(绝对和或相对的),必选项。
   s = f.Path.toUpperCase() + "<br>"; //文件路径
   s += "建立时间: " + f.DateCreated + " ";
   s += "最后访问时间: " + f.DateLastAccessed + " ";
   s += "最后修改时间: " + f.DateLastModified;
}

var filespec = "E:\\1.doc";

 

posted @ 2012-09-04 09:31  尹成亮  阅读(603)  评论(0编辑  收藏  举报