static void ShowFolderInfo(CustomFolderInfo item) { item.PrintFolderInfo(); ConsoleKeyInfo pressedKey = Console.ReadKey(); //работаем с клавиатурой if (pressedKey.Key == ConsoleKey.UpArrow) { item.DecreaseIndex(); ShowFolderInfo(item); } else if (pressedKey.Key == ConsoleKey.DownArrow) { item.IncreaseIndex(); ShowFolderInfo(item); } else if (pressedKey.Key == ConsoleKey.Enter) { CustomFolderInfo newItem = item.GetNextItem(); ShowFolderInfo(newItem); } else if (pressedKey.Key == ConsoleKey.Escape) { CustomFolderInfo newItem = item.GetPrevItem(); ShowFolderInfo(newItem); } }
public CustomFolderInfo GetNextItem() { FileSystemInfo active = objs[index]; if (active.GetType() == typeof(DirectoryInfo))// если { List <FileSystemInfo> list = new List <FileSystemInfo>(); DirectoryInfo d = (DirectoryInfo)active; list.AddRange(d.GetDirectories()); list.AddRange(d.GetFiles()); CustomFolderInfo x = new CustomFolderInfo(this, 0, list.ToArray()); return(x); } else { Console.Clear(); FileStream fs = new FileStream(active.FullName, FileMode.Open, FileAccess.Read); //открываем и получаем доступ к файлу StreamReader sr = new StreamReader(fs); //читаем строку в файле Console.WriteLine(sr.ReadToEnd()); sr.Close(); fs.Close(); } return(null); }
static void Main(string[] args) { List <FileSystemInfo> list = new List <FileSystemInfo>(); var d = new DirectoryInfo(@"C:\"); list.AddRange(d.GetDirectories()); //возвращает имена подкаталогов list.AddRange(d.GetFiles()); //возвращает имена файлов, включая пути CustomFolderInfo test = new CustomFolderInfo(null, 0, list.ToArray()); ShowFolderInfo(test); }
FileSystemInfo[] objs; //свойство для чтения, создания, удаления файла public CustomFolderInfo(CustomFolderInfo prev, int index, FileSystemInfo[] objs) //конструктор с тремя аргументами { this.prev = prev; this.index = index; this.objs = objs; }