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

.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";

 

转载于:https://www.cnblogs.com/yinchengliang/archive/2012/09/04/2669923.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值