Esempio n. 1
0
        private void GetCFileByOneLevel(string ext, bool isOnlyDirectory, ECFile root)
        {
            DirectoryInfo dir = new DirectoryInfo(root.FullName);
            DirectoryInfo[] childrens = dir.GetDirectories();
            if (childrens != null && childrens.Length > 0)
            {
                if (root.Children == null) root.Children = new List<ECFile>();
                foreach (var item in childrens)
                {
                    if (_exceptDirs.Contains(item.Name)) continue;
                    root.Children.Add(new ECFile()
                    {
                        ParentFullName = item.Parent.FullName,
                        FullName = item.FullName,
                        Name = item.Name,
                        Extension = item.Extension,
                        LastWriteTime = item.LastWriteTime,
                        CreateTime = item.CreationTime,
                        IsDirectory = true
                    });
                }
            }
            if (!isOnlyDirectory)
            {
                FileInfo[] fs = this.GetFiles(root.FullName, ext);
                if (fs != null && fs.Length > 0)
                {
                    if (root.Children == null) root.Children = new List<ECFile>();

                    foreach (var item in fs)
                    {
                        root.Children.Add(new ECFile()
                        {
                            FullName = item.FullName,
                            Name = item.Name,
                            Extension = item.Extension,
                            LastWriteTime = item.LastWriteTime,
                            CreateTime = item.CreationTime,
                            Length = item.Length,
                            DownloadUrl = GetDownloadUrl(item.FullName),
                            IsDirectory = false
                        });
                    }
                }
            }
        }
Esempio n. 2
0
        public ECFile GetCFileTreeByOnlyDirectory(string path)
        {
            string rootPath = HttpContext.Current.Server.MapPath(@"\");
            rootPath = path.HasValue() ? Path.Combine(rootPath, path) : rootPath;

            DirectoryInfo dir = new DirectoryInfo(rootPath);
            ECFile root = new ECFile
            {
                ParentFullName = dir.Parent.FullName,
                FullName = dir.FullName,
                Name = dir.Name,
                Extension = dir.Extension,
                LastWriteTime = dir.LastWriteTime,
                CreateTime = dir.CreationTime,
                IsDirectory = true
            };
            this.GetCFileTree("*.*", true, root);
            return root;
        }
Esempio n. 3
0
 private void GetCFileTree(string ext, bool isOnlyDirectory, ECFile root)
 {
     GetCFileByOneLevel(ext, isOnlyDirectory, root);
     if (root.Children != null)
     {
         foreach (var item in root.Children)
         {
             if (Directory.Exists(item.FullName))
             {
                 GetCFileTree(ext, isOnlyDirectory, item);
             }
         }
     }
 }