对于前面一篇的关于获取文件夹及其子文件夹的文件信息,使用起来不是很方便,于是更新了下,加点信息,这样以后判断两个文件夹的内容是否相等,差异等更方便.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
public class CFileVer { public string FilePath { get; set; } public string FileName { get; set; } public string FileDate { get; set; } public string FileVersion { get; set; } } public List<CFileVer> getAllFileVer(string RootPath, string RootFormat) { List<CFileVer> lstFile = new List<CFileVer>(); DirectoryInfo TheFolder = new DirectoryInfo(RootPath); FileSystemInfo[] files = TheFolder.GetFileSystemInfos(); foreach (FileSystemInfo item in files) { if (item.Attributes.ToString() == "Directory") { lstFile.AddRange(getAllFileVer(item.FullName, RootFormat)); } else { FileVersionInfo fileInfo = FileVersionInfo.GetVersionInfo(RootPath + "\\" + item.Name); lstFile.Add(new CFileVer { FilePath = RootPath.Replace(RootFormat, "Root"), FileName = item.Name, FileVersion = string.Format(@"{0}.{1}.{2}.{3}", fileInfo.FileMajorPart, fileInfo.FileMinorPart, fileInfo.FileBuildPart, fileInfo.FilePrivatePart), FileDate = item.LastWriteTime.ToString("yyyy-MM-dd hh:mm:ss") }); } } return lstFile; } |