예제 #1
0
        /// <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 = "[<b><font color=red>Superior</font></b>]";
                topitem.FullName = topdi.FullName;
                list.Insert(0, topitem);

                FileSystemItem rootitem = new FileSystemItem();
                DirectoryInfo rootdi = new DirectoryInfo(strRootFolder);
                rootitem.Name = "[<b><font color=red>Root</font></b>]";
                rootitem.FullName = rootdi.FullName;
                list.Insert(0, rootitem);

            }
            return list;
        }
예제 #2
0
        /// <summary>
        /// �г�Ŀ¼�ڵ������ļ�
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public static List<FileSystemItem> GetItemsAll(string path)
        {
            //FileInfo[] file = HelloData.Common.SystemCms.GetFilelist(path);
            List<FileSystemItem> list = new List<FileSystemItem>();
            //for (int i = 0; i < file.Length; i++)
            //{
            //    FileSystemItem item = new FileSystemItem();
            //    item.Name = file[i].Name.Replace(path,"");
            //    item.FullName = file[i].FullName;
            //    item.CreationDate = file[i].CreationTime;
            //    item.IsFolder = true;
            //    item.Size = file[i].Length;
            //    list.Add(item);
            //}

            DirectoryInfo UnPostil = new DirectoryInfo(path);
            FileInfo[] ArrUnPostil = UnPostil.GetFiles();

            foreach (FileInfo FileName in ArrUnPostil)
            {
                if (FileName.Length > 0)
                {
                    FileSystemItem item = new FileSystemItem();
                    item.Name = FileName.Name.Replace(path, "");
                    item.FullName = FileName.FullName;
                    item.CreationDate = FileName.CreationTime;
                    item.IsFolder = true;
                    item.Size = FileName.Length;
                    list.Add(item);
                }
            }

            return list;
        }
예제 #3
0
 /// <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;
 }