Beispiel #1
0
        protected void GetChildItems(List <FileDir> list, IEnumerable <IListBlobItem> items, GetItemsOptions options, FileDir parentDir)
        {
            foreach (IListBlobItem item in items)
            {
                if (item.GetType() == typeof(CloudBlockBlob))
                {
                    if (options.HasFlag(GetItemsOptions.IncludeFiles))
                    {
                        list.Add(FromBlob((CloudBlockBlob)item));
                    }

                    if (parentDir != null)
                    {
                        parentDir.Length++;
                    }
                }
                else if (options.HasFlag(GetItemsOptions.IncludeDirectories) && item.GetType() == typeof(CloudBlobDirectory))
                {
                    CloudBlobDirectory bdir     = (CloudBlobDirectory)item;
                    string             pname    = bdir.Parent == null?"":bdir.Parent.Prefix;
                    FileDir            childDir = new FileDir()
                    {
                        Name = bdir.Prefix.Substring(pname.Length, bdir.Prefix.Length - pname.Length - 1), IsDirectory = true, Path = pname
                    };
                    list.Add(childDir);
                    if (options.HasFlag(GetItemsOptions.Deep))
                    {
                        GetChildItems(list, bdir.ListBlobs(), options, childDir);
                    }
                }
            }
        }
Beispiel #2
0
 protected void GetChildItems(List <FileDir> items, DirectoryInfo di, GetItemsOptions options, int prefixLength)
 {
     if (options.HasFlag(GetItemsOptions.IncludeFiles))
     {
         foreach (FileInfo fi in di.GetFiles())
         {
             items.Add(FromFI(fi, prefixLength));
         }
     }
     if (options.HasFlag(GetItemsOptions.IncludeDirectories))
     {
         foreach (DirectoryInfo cdi in di.GetDirectories())
         {
             items.Add(new FileDir()
             {
                 Name = cdi.Name, IsDirectory = true, Path = cdi.Parent.FullName.Length <= prefixLength?"": (cdi.Parent.FullName.Substring(prefixLength) + "\\")
             });
             if (options.HasFlag(GetItemsOptions.Deep))
             {
                 GetChildItems(items, cdi, options, prefixLength);
             }
         }
     }
 }