在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
根据文件名获取文件1 /// <summary> 2 /// 根据文件名获取文件 3 /// </summary> 4 /// <param name="directory"></param> 5 /// <param name="fileName"></param> 6 /// <param name="searchOption"></param> 7 /// <returns></returns> 8 private FileInfo[] GetFile(string directory, string fileName, SearchOption searchOption) 9 { 10 DirectoryInfo directoryInfo = new DirectoryInfo(directory); 11 if (!directoryInfo.Exists) 12 return null; 13 14 return directoryInfo.GetFiles(fileName, searchOption); 15 } 删除过期目录1 /// <summary> 2 /// 删除过期目录 3 /// </summary> 4 /// <param name="directory">根目录</param> 5 /// <param name="day">期限</param> 6 /// <returns></returns> 7 private int DelectOverdueDirectorys(string directory, int day) 8 { 9 DirectoryInfo directoryInfoRoot = new DirectoryInfo(directory); 10 if (!directoryInfoRoot.Exists) 11 return 1; 12 13 DirectoryInfo[] directoryInfos = directoryInfoRoot.GetDirectories(); 14 foreach (var directoryInfo in directoryInfos) 15 { 16 if (DateTime.Now.Subtract(directoryInfo.CreationTime).TotalDays > day) 17 directoryInfo.Delete(true); 18 } 19 20 return 0; 21 } 删除过期文件1 /// <summary> 2 /// 删除过期文件 3 /// </summary> 4 /// <param name="directory">根目录</param> 5 /// <param name="day">期限</param> 6 /// <returns></returns> 7 private int DelectOverdueFiles(string directory, int day) 8 { 9 DirectoryInfo directoryInfoRoot = new DirectoryInfo(directory); 10 if (!directoryInfoRoot.Exists) 11 return 1; 12 13 FileInfo[] fileInfos = directoryInfoRoot.GetFiles(); 14 foreach (var fileInfo in fileInfos) 15 { 16 if (DateTime.Now.Subtract(fileInfo.CreationTime).TotalDays > day) 17 fileInfo.Delete(); 18 } 19 20 return 0; 21 } 设置目录隐藏1 /// <summary> 2 /// 设置目录隐藏 3 /// </summary> 4 /// <param name="directory"></param> 5 /// <returns></returns> 6 private int SetDirectoryHide(string directory) 7 { 8 DirectoryInfo directoryInfo = new DirectoryInfo(directory); 9 if (!directoryInfo.Exists) 10 return 1; 11 12 directoryInfo.Attributes = FileAttributes.Hidden; 13 return 0; 14 } 目录加解锁1 string FileExtend = ".{2559a1f2-21d7-11d4-bdaf-00c04f60b9f0}"; 2 3 /// <summary> 4 /// 目录加锁 5 /// </summary> 6 /// <param name="directory"></param> 7 /// <returns></returns> 8 private int DirectoryEncrypt(string directory) 9 { 10 DirectoryInfo directoryInfo = new DirectoryInfo(directory); 11 if (!directoryInfo.Exists) 12 return 1; 13 14 directoryInfo.MoveTo(directory + FileExtend); 15 return 0; 16 } 17 18 /// <summary> 19 /// 目录解锁 20 /// </summary> 21 /// <param name="directory"></param> 22 /// <returns></returns> 23 private int DirectoryDecrypt(string directory) 24 { 25 DirectoryInfo directoryInfo = new DirectoryInfo(directory + FileExtend); 26 if (!directoryInfo.Exists) 27 return 1; 28 29 directoryInfo.MoveTo(directory); 30 return 0; 31 }
|
请发表评论