/// <summary> /// 读取列表 /// </summary> /// <param name="path"></param> /// <returns></returns> public static List<FileSystemItem> GetItems(string path) { string[] folders = Directory.GetDirectories(path); string[] files = Directory.GetFiles(path); List<FileSystemItem> list = new List<FileSystemItem>(); foreach (string s in folders) { FileSystemItem item = new FileSystemItem(); 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) { FileSystemItem item = new FileSystemItem(); 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()) { FileSystemItem topitem = new FileSystemItem(); DirectoryInfo topdi = new DirectoryInfo(path).Parent; topitem.Name = "[上一级]"; topitem.FullName = topdi.FullName; list.Insert(0, topitem); FileSystemItem rootitem = new FileSystemItem(); DirectoryInfo rootdi = new DirectoryInfo(strRootFolder); rootitem.Name = "[根目录]"; rootitem.FullName = rootdi.FullName; list.Insert(0, rootitem); } return list; }
/// <summary> /// 读取文件信息 /// </summary> /// <param name="path"></param> /// <returns></returns> public static FileSystemItem GetItemInfo(string path) { FileSystemItem item = new FileSystemItem(); 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; }