void InternalListItems(List<IStorageItem> result ,StorageDirectory dir, bool includeSubs = false, StorageTypes itemType = StorageTypes.All) { var dirInfo = (dir.FileSystemInfo as DirectoryInfo); if (itemType.IsFile()) { var subInfos = dirInfo .GetFiles(); foreach (var sub in subInfos) { result.Add(new StorageFile(sub, dir,this.InternalStorage)); } } if (itemType.IsDirectory() || includeSubs) { var subs = dirInfo.GetDirectories(); foreach (var sub in subs) { var subItem = new StorageDirectory(sub, dir, this.InternalStorage); if(itemType.IsDirectory())result.Add(subItem); if (includeSubs) InternalListItems(result, subItem, includeSubs, itemType); } } }
public IStorageItem GetItem(string path, StorageTypes itemType = StorageTypes.All,bool createIfNotExisted=false) { var absolutePath = new AbsolutePath(path, this); if (itemType.IsDirectory()) { if (System.IO.Directory.Exists(absolutePath)) { return new StorageDirectory(new DirectoryInfo(absolutePath), null, absolutePath.Storage); } else if(createIfNotExisted){ var dir = new DirectoryInfo(absolutePath); dir.Create(); return new StorageDirectory(dir, null, absolutePath.Storage); } } if (itemType.IsFile()) { if (System.IO.File.Exists(absolutePath)) { return new StorageFile(new FileInfo(absolutePath), null, absolutePath.Storage); } else if(createIfNotExisted){ var info = new FileInfo(absolutePath); if (!info.Directory.Exists) info.Directory.Create(); using (var s = info.Create()) { }; return new StorageFile(info, null, absolutePath.Storage); } } return null; }
public IList<IStorageItem> ListItems(string path, StorageTypes itemType = StorageTypes.All) { var filename = new AbsolutePath(path , this); if (!System.IO.Directory.Exists(filename)) return null; var result = new List<IStorageItem>(); if (itemType.IsFile()) { var filenames = System.IO.Directory.GetFiles(filename); foreach(var name in filenames) result.Add(new StorageFile(new FileInfo(name),this,filename.Storage)); } if (itemType.IsDirectory()) { path += "/"; var filenames = System.IO.Directory.GetDirectories(filename); foreach (var name in filenames) result.Add(new StorageDirectory(new DirectoryInfo(name),this,filename.Storage)); } return result; }