Esempio n. 1
0
        public static FolderContainer Create(DirectoryInfo dirInfo)
        {
            FolderContainer result = new FolderContainer(dirInfo.Name, dirInfo.LastWriteTime);

            result.Add(
                from folder in dirInfo.GetDirectories()
                select Create(folder)
                );
            result.Add(
                from info in dirInfo.GetFiles()
                select new FileContainer(info)
                );
            return(result);
        }
Esempio n. 2
0
        public static FolderContainer Create(IEnumerable <FileInfo> fileInfos)
        {
            if (fileInfos.Count() == 0)
            {
                throw new ArgumentException("Empty file list.");
            }

            if (fileInfos.Count() == 1)
            {
                FileInfo file = fileInfos.Single();
                if (IsDirectory(file))
                {
                    return(Create(new DirectoryInfo(file.FullName)));
                }
                else
                {
                    FolderContainer folder = CreateEmpty(file.Name);
                    folder.Add(new FileContainer(file));
                    return(folder);
                }
            }

            FolderContainer result = CreateEmpty(fileInfos.First().Directory.Name);

            result.Add(
                from folder in fileInfos
                where IsDirectory(folder)
                select Create(new DirectoryInfo(folder.FullName))
                );
            result.Add(
                from info in fileInfos
                where !IsDirectory(info)
                select new FileContainer(info)
                );
            return(result);
        }