コード例 #1
0
        public static dirStructure GetRoot()
        {
            dirStructure currentDirStruct = new dirStructure();

            currentDirStruct.Folders = new List <string>();
            currentDirStruct.Files   = new List <string>();

            currentDirStruct.CurrentPath = "";
            var currentDrives = DriveInfo.GetDrives().Where(d => d.DriveType == DriveType.Fixed && d.IsReady);

            foreach (var drive in currentDrives)
            {
                currentDirStruct.Folders.Add(drive.Name);
            }
            return(currentDirStruct);
        }
コード例 #2
0
        public static dirStructure GetDir(string currentFolder)
        {
            if (!Directory.Exists(currentFolder))
            {
                return(null);
            }

            dirStructure currentDirStruct = new dirStructure();

            currentDirStruct.Folders = new List <string>();
            currentDirStruct.Files   = new List <string>();

            DirectoryInfo dirinfoFolder = new DirectoryInfo(currentFolder);

            try
            {
                currentDirStruct.CurrentPath = currentFolder;

                var Directories = dirinfoFolder.GetDirectories("*.*", SearchOption.TopDirectoryOnly);

                foreach (var dir in Directories)
                {
                    currentDirStruct.Folders.Add(dir.Name);
                }
            }
            catch (Exception)
            {
                return(null);
            }
            var DirFiles = dirinfoFolder.GetFiles("*.*", SearchOption.TopDirectoryOnly);

            foreach (var file in DirFiles)
            {
                currentDirStruct.Files.Add(file.Name);
            }

            return(currentDirStruct);
        }