/// <summary> /// 读取列表 /// </summary> /// <param name="path"></param> /// <returns></returns> public static List<FileManager> GetItems(string path) { string[] folders = Directory.GetDirectories(path); string[] files = Directory.GetFiles(path); List<FileManager> list = new List<FileManager>(); foreach (string s in folders) { FileManager item = new FileManager(); DirectoryInfo di = new DirectoryInfo(s); item.Name = di.Name; item.FullName = di.FullName; item.CreationDate = di.CreationTime; item.IsFolder = true; list.Add(item); } foreach (string s in files) { FileManager item = new FileManager(); FileInfo fi = new FileInfo(s); item.Name = fi.Name; item.FullName = fi.FullName; item.CreationDate = fi.CreationTime; item.IsFolder = true; item.Size = fi.Length; list.Add(item); } if (path.ToLower() != strRootFolder.ToLower()) { FileManager topitem = new FileManager(); DirectoryInfo topdi = new DirectoryInfo(path).Parent; topitem.Name = "[<b><font color=red>Superior</font></b>]"; topitem.FullName = topdi.FullName; list.Insert(0, topitem); FileManager rootitem = new FileManager(); DirectoryInfo rootdi = new DirectoryInfo(strRootFolder); rootitem.Name = "[<b><font color=red>Root</font></b>]"; rootitem.FullName = rootdi.FullName; list.Insert(0, rootitem); } return list; }
/// <summary> /// 读取文件信息 /// </summary> /// <param name="path"></param> /// <returns></returns> public static FileManager GetItemInfo(string path) { FileManager item = new FileManager(); if (Directory.Exists(path)) { DirectoryInfo di = new DirectoryInfo(path); item.Name = di.Name; item.FullName = di.FullName; item.CreationDate = di.CreationTime; item.IsFolder = true; item.LastAccessDate = di.LastAccessTime; item.LastWriteDate = di.LastWriteTime; item.FileCount = di.GetFiles().Length; item.SubFolderCount = di.GetDirectories().Length; } else { FileInfo fi = new FileInfo(path); item.Name = fi.Name; item.FullName = fi.FullName; item.CreationDate = fi.CreationTime; item.LastAccessDate = fi.LastAccessTime; item.LastWriteDate = fi.LastWriteTime; item.IsFolder = false; item.Size = fi.Length; } return item; }