Example #1
0
        public IEnumerable<FileSystemObject> GetDirectoryListing(FileSystemObject fso)
        {
            if (fso == null) throw new ArgumentNullException("fso");
            if (fso.Type == FsType.File) throw new ArgumentException("Cannot get directory listing from a file");

            var driveOrDirName = GetFullname(fso);

            if (string.IsNullOrWhiteSpace(driveOrDirName)) throw new ArgumentException("Cannot get directory listing from an empty path");

            // First, get the directories
            var dirs = from d in Directory.GetDirectories(driveOrDirName)
                        select new FileSystemObject
                            {
                                Fullname = d,
                                Name = Path.GetFileName(d),
                                Type = FsType.Directory
                            };

            // Then get the files
            dirs = dirs.Concat(from f in Directory.GetFiles(driveOrDirName)
                                select new FileSystemObject
                                    {
                                        Fullname = f,
                                        Name = Path.GetFileName(f),
                                        Type = FsType.File
                                    });

            return dirs;
        }
Example #2
0
 private string GetFullname(FileSystemObject fso)
 {
     switch (fso.Type)
     {
         case FsType.Directory:
             return fso.Fullname;
         case FsType.Drive:
             return fso.Name;
         default:
             throw new NotImplementedException(string.Format("Getting directory listing for FileSystemObject type {0} is not implemented", fso.Type));
     }
 }
Example #3
0
        public IEnumerable<FileSystemObject> GetDirectories(FileSystemObject drive)
        {
            var dirs =  _filesystemDao.GetDirectoryListing(drive);

            var fsObjects = from d in dirs
                            select new FileSystemObject
                                {
                                    Fullname = d.Fullname,
                                    Name = d.Name,
                                    Type = FsType.Directory
                                };
            return fsObjects;
        }