-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
86 lines (80 loc) · 2.5 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FileTest
{
class Program
{
static void print(List<Object> entries, int pos)
{
Console.SetCursorPosition(0, 0);
int cur = 0;
foreach (Object obj in entries)
{
if (cur == pos)
{
Console.BackgroundColor = ConsoleColor.Green;
} else
{
Console.BackgroundColor = ConsoleColor.Black;
}
cur = cur + 1;
if (obj is DirectoryInfo)
{
Console.ForegroundColor = ConsoleColor.Magenta;
Console.WriteLine(((DirectoryInfo)obj).Name);
} else
{
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine(((FileInfo)obj).Name);
}
}
}
static void Main(string[] args)
{
string path = @"C:\Users\Admin\Desktop";
DirectoryInfo directory = new DirectoryInfo(path);
FileInfo[] files = directory.GetFiles();
DirectoryInfo[] directories = directory.GetDirectories();
List<Object> entries = new List<Object>();
foreach (DirectoryInfo directory1 in directories)
{
entries.Add(directory1);
}
foreach (FileInfo file in files)
{
entries.Add(file);
}
int pos = 0;
while (true)
{
print(entries, pos);
ConsoleKeyInfo key = Console.ReadKey();
if (key.Key == ConsoleKey.UpArrow)
{
if (pos > 0)
{
pos--;
} else
{
pos = entries.Count - 1;
}
} else if (key.Key == ConsoleKey.DownArrow)
{
if (pos + 1 < entries.Count)
{
pos++;
} else
{
pos = 0;
}
} else
{
}
}
}
}
}