コード例 #1
0
ファイル: Program.cs プロジェクト: Aigerimmsadir/Midterm2
        static void Main(string[] args)
        {
            Console.WriteLine("Please enter the word you need to find");
            string k = Console.ReadLine();

            Console.ForegroundColor = ConsoleColor.Blue;
            List <FileSystemInfo> list = new List <FileSystemInfo>();
            var d = new DirectoryInfo(@"C:\Users\Lenovo\Desktop\pois");

            list.AddRange(d.GetDirectories());
            list.AddRange(d.GetFiles());
            int num = 0;
            CustomFolderInfo test = new CustomFolderInfo(null, list.ToArray());

            Zapis(test);
            Console.WriteLine("The word has been found in:");
            for (int i = 0; i < Global.tuples.Count; i++)
            {
                string[] ss = Global.tuples[i].Item2.Split(' ');
                for (int j = 0; j < ss.Length; j++)
                {
                    if (ss[j] == k)
                    {
                        Console.ForegroundColor = ConsoleColor.DarkMagenta;
                        Console.WriteLine(Global.tuples[i].Item1);
                        num++;
                    }
                }
            }
            if (num == 0)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("File with this word doesn't exist");
            }
        }
コード例 #2
0
            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)
                {
                    if (item.objs[item.index].GetType() == typeof(DirectoryInfo))

                    {
                        CustomFolderInfo newItem = item.GetNextItem();
                        ShowFolderInfo(newItem);
                    }
                    else
                    {
                        if (item.objs[item.index].Extension == ".txt")
                        {
                            Console.Clear();
                            FileInfo d = (FileInfo)item.objs[item.index];

                            string line;
                            List <FileSystemInfo> list = new List <FileSystemInfo>();
                            string       s             = d.FullName;
                            StreamReader file          = new StreamReader(s);
                            while ((line = file.ReadLine()) != null)
                            {
                                Console.Clear();
                                Console.WriteLine(line);
                            }
                            ConsoleKeyInfo newpressedKey = Console.ReadKey();
                            if (newpressedKey.Key == ConsoleKey.Escape)
                            {
                                ShowFolderInfo(item);
                            }
                        }
                    }
                }
                else if (pressedKey.Key == ConsoleKey.Escape)
                {
                    CustomFolderInfo newItem = item.GetPrevItem();
                    ShowFolderInfo(newItem);
                }
            }
コード例 #3
0
ファイル: Program.cs プロジェクト: Aigerimmsadir/Midterm2
        public CustomFolderInfo GetNextItem(int k)
        {
            FileSystemInfo        active = objs[k];
            List <FileSystemInfo> list   = new List <FileSystemInfo>();
            DirectoryInfo         d      = active as DirectoryInfo;

            list.AddRange(d.GetDirectories());
            list.AddRange(d.GetFiles());
            CustomFolderInfo x = new CustomFolderInfo(this, list.ToArray());

            return(x);
        }
コード例 #4
0
        public CustomFolderInfo GetNextItem()
        {
            FileSystemInfo        active = objs[index];
            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);
        }
コード例 #5
0
            static void Main(string[] args)
            {
                Console.BackgroundColor = ConsoleColor.DarkBlue;
                List <FileSystemInfo> list = new List <FileSystemInfo>();
                var d = new DirectoryInfo(@"C:\Users\Lenovo\Desktop\work");

                list.AddRange(d.GetDirectories());
                list.AddRange(d.GetFiles());

                CustomFolderInfo test = new CustomFolderInfo(null, 0, list.ToArray());

                ShowFolderInfo(test);
            }
コード例 #6
0
ファイル: Program.cs プロジェクト: Aigerimmsadir/Midterm2
        static void Zapis(CustomFolderInfo item)
        {
            for (int i = 0; i < item.objs.Length; ++i)
            {
                if (item.objs[i].GetType() == typeof(FileInfo))
                {
                    if (item.objs[i].Extension == ".txt")
                    {
                        FileInfo d = (FileInfo)item.objs[i];
                        ///  string mydocpath = @"C:\Users\Lenovo\Desktop\Новая папка";
                        string line;
                        string s = d.FullName;

                        string       res  = Path.GetFileName(s);
                        StreamReader file = new StreamReader(s);
                        while ((line = file.ReadLine()) != null)
                        {
                            ///   using (StreamWriter outputFile = new StreamWriter((mydocpath + @"\lol.txt"), true))
                            ///   {

                            Tuple <string, string> pair = new Tuple <string, string>(res, line);
                            Global.tuples.Add(pair);

                            ///   outputFile.WriteLine(line);

                            /// }
                        }
                    }
                }

                else
                {
                    CustomFolderInfo newItem = item.GetNextItem(i);
                    Zapis(newItem);
                }
            }
        }
コード例 #7
0
ファイル: Program.cs プロジェクト: Aigerimmsadir/Midterm2
 public CustomFolderInfo(CustomFolderInfo prev, FileSystemInfo[] list)
 {
     this.prev = prev;
     this.objs = list;
 }
コード例 #8
0
 public CustomFolderInfo(CustomFolderInfo prev, int index, FileSystemInfo[] list)
 {
     this.prev  = prev;
     this.index = index;
     this.objs  = list;
 }