阅读:199 点赞:1 评论:0
199
想要获取本地文件的数据,类似于很简单的时间,名称,大小。
用于创建文件后的校验和信息获取。发现c#有个很简单的类
引用
using System.IO;
定义一个存储类
///
/// 地图文件 信息
///
public class T_SitemapFile
{
///
/// 是否存在
///
public bool Exists { get; set; }
///
/// 添加时间
///
public string AddTime { get; set; }
///
/// 文件名
///
public string FileName { get; set; }
///
/// 文件大小
///
public string Length { get; set; }
}
然后就是查询的方式
///
/// 获取文件信息
///
///
///
///
public static T_SitemapFile Get_FileInfo(string Save_Path, string FileName = "Sitemap.xml")
{
T_SitemapFile Info = new T_SitemapFile();
Info.Exists = File.Exists(Save_Path + "/" + FileName);
if (Info.Exists)
{
FileInfo temp = new FileInfo(Save_Path + "/" + FileName);
Info.AddTime = temp.CreationTime.ToString();
Info.FileName = temp.Name;
Info.Length = temp.Length.ToString ();
}
return Info;
}
之前一直觉得查文件感觉很麻烦,没想到这么简单,做个笔记记录一下,以后要用的时候没准还会用到
编写于:2021/12/1 16:11:58
版权声明
编写于:2021/12/1 16:11:58
本站内容均来自网络转载或网友提供,如有侵权请及时联系我们删除!本站不承担任何争议和法律责任!