Skip to content

Commit c26d890

Browse files
committed
SimpleFileExplorer basic
1 parent 699f7ac commit c26d890

File tree

3 files changed

+70
-1
lines changed

3 files changed

+70
-1
lines changed

.gitignore

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,10 @@ obj/ProgramingChallenges.csproj.nuget.g.props
44
obj/ProgramingChallenges.csproj.nuget.g.targets
55
obj/project.assets.json
66
Polygon/*
7-
.vscode
7+
.vscode
8+
challenges/bin
9+
challenges/obj
10+
challenges/Properties
11+
challenges/ProgrammingChallenges.csproj
12+
challenges/ProgrammingChallenges.csproj.user
13+
challenges/.vs

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ If you have any questions, you can contact me by email morasiu2@gmail.com
2424
* [14 Magic 8-ball](#14)
2525
* [15 Collatz Conjecture](#15)
2626
* [16 Reverse String](#16)
27+
* [~~17 Eurelian Path~~](#17)
28+
* [18 Simple File Explorer](#18)
2729

2830
## Bonus
2931

@@ -80,5 +82,9 @@ Yeah, so... Reverse string isn't that hard so I've made one-liner challenge
8082
string.Concat(text.Reverse())
8183
```
8284
![16](docs/images/16.png)
85+
* <a name="17">17</a>~~Eurelian Path~~<br>
86+
Why I didn't solve that challenge? It sounds fun, but I hate writing GUI and that would be a nightmare for me.
87+
Maybe some day?
88+
* <a name="18">18</a> Simple file Explorer *Pending* (`C#`)<br>
8389
## Bonus
8490
* <a name="bonus1">Bonus 1</a> Loading animation in console 24.02.2018 *Done* (`C#`)![Bonus 1](docs/images/bonus1.gif)
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
using System;
2+
using System.Collections;
3+
using System.Collections.Generic;
4+
using System.IO;
5+
using System.Linq;
6+
using System.Linq.Expressions;
7+
using System.Reflection.Metadata.Ecma335;
8+
9+
class SimpleFileExplorer {
10+
static void Main(string[] args) {
11+
Console.ForegroundColor = ConsoleColor.Green;
12+
Console.WriteLine("<--------Simple File Explorer--------->");
13+
Console.WriteLine("Created by Morasiu (morasiu2@gmail.com)");
14+
15+
Start();
16+
}
17+
18+
static void Start() {
19+
Console.Clear();
20+
Console.WriteLine("..");
21+
var files = Directory.GetFiles(Directory.GetCurrentDirectory()).ToList();
22+
//var files = Directory.GetFiles(@"c:\Users\hmorawski\Downloads").ToList();
23+
foreach (var file in files) {
24+
var fileName = Path.GetFileName(file);
25+
var line = fileName;
26+
var fileSize = GetFileSize(new FileInfo(file).Length);
27+
for (var i = 0; i < Console.WindowWidth - fileName.Length - fileSize.Length - 1; i++) {
28+
line += " ";
29+
}
30+
31+
line += fileSize;
32+
Console.WriteLine(line);
33+
}
34+
35+
MakeEmptyLines(files);
36+
37+
Console.Write(" q - Quit");
38+
var key = Console.ReadKey().Key;
39+
if (key == ConsoleKey.Q) Environment.Exit(0);
40+
}
41+
42+
private static string GetFileSize(long size) {
43+
var convertedSize = "Error";
44+
if (size < 1000) convertedSize = size + " B";
45+
else if (size < 1000 * 1000) convertedSize = (size / 1000) + " KB";
46+
else if (size < 1000 * 1000 * 1000) convertedSize = size / (1000 * 1000) + " MB";
47+
else if (size >= 1000 * 1000 * 1000) convertedSize = size / (1000 * 1000 * 1000) + " GB";
48+
49+
return convertedSize;
50+
}
51+
52+
private static void MakeEmptyLines(ICollection files) {
53+
for (var i = 0; i < Console.WindowHeight - files.Count - 2; i++) {
54+
Console.WriteLine();
55+
}
56+
}
57+
}

0 commit comments

Comments
 (0)