Exemple #1
0
        public DirectoryInfo GetDir(string path, FileSource source = FileSource.All, int remainingdepth = -1)
        {
            if(remainingdepth == -1)
                remainingdepth = DirInfoMaxRecursionDepth;
            var result = new DirectoryInfo
            {
                Subdirectories = new List<DirectoryInfo>(),
                Files = new List<string>(),
                Name = String.IsNullOrWhiteSpace(path) ? "<>" : Path.GetFileName(path)
            };

            if(source.HasFlag(FileSource.LocalUserData) && !Path.IsPathRooted(path))
            {
                string userdatapath = Path.Combine(DataFolder, path);
                if (Directory.Exists(userdatapath))
                {
                    if (remainingdepth > 0)
                        foreach (string directory in Directory.GetDirectories(userdatapath))
                        {
                            var dirinfo = GetDir(directory, FileSource.Local, remainingdepth - 1); //Iterate as local since it's now a complete Path
                            result.Subdirectories.Add(dirinfo);
                        }
                    result.Files.AddRange(Directory.GetFiles(userdatapath).Select(Path.GetFileName));
                }
            }

            if (source.HasFlag(FileSource.Local))
            {
                string localpath = Path.IsPathRooted(path) ? path : Path.Combine(Environment.CurrentDirectory, path);
                if (Directory.Exists(localpath))
                {
                    if (remainingdepth > 0)
                        foreach (string directory in Directory.GetDirectories(localpath))
                            result.Subdirectories.Add(GetDir(directory, FileSource.Local, remainingdepth - 1));
                    result.Files.AddRange(Directory.GetFiles(localpath).Select(Path.GetFileName));
                }
            }

            //ToDo: Iterate on compressed FS and network FS

            return RemoveDoubleFiles(result);
        }