-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
100 lines (97 loc) · 2.21 KB
/
Program.cs
File metadata and controls
100 lines (97 loc) · 2.21 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
using System;
using System.IO;
namespace FillHDD
{
class MainClass
{
public static void Main (string[] args)
{
int length;
string option;
string filename = "Dummy";
start:
Console.WriteLine ("Type the numer and press enter");
Console.WriteLine ("1) Fill a drive");
Console.WriteLine ("2) Enter a file size");
option = Console.ReadLine ();
if (option == "1")
{
string drive;
Console.WriteLine ("Enter the drive letter (C:)");
drive = Console.ReadLine ();
string freespace = GetTotalFreeSpace (drive).ToString();
Console.WriteLine("Drive " + drive + " has " + freespace + "free");
length = Convert.ToInt32(freespace);
Console.WriteLine ("Do you want to fill that up? (Y/N)");
option = Console.ReadLine ();
if (option == "Y" || option == "y")
{
CreateDummyFile (drive + "\\" + filename, length);
}
else
{
if (option == "N" || option == "n")
{
goto start;
}
else
{
Console.WriteLine ("Invalid value");
goto start;
}
}
}
else
{
if (option == "2")
{
Console.WriteLine ("Enter the size of the file (MB)");
length = Convert.ToInt16(Console.ReadLine ());
Console.WriteLine ("Do you want to create a " + length.ToString() + " MB file? (Y/N)");
option = Console.ReadLine ();
if (option == "Y" || option == "y")
{
CreateDummyFile (filename, length);
}
else
{
if (option == "N" || option == "n")
{
goto start;
}
else
{
Console.WriteLine ("Invalid value");
goto start;
}
}
}
else
{
Console.WriteLine ("Invalid value");
goto start;
}
Console.ReadLine ();
}
}
public static long GetTotalFreeSpace(string driveName)
{
foreach (DriveInfo drive in DriveInfo.GetDrives())
{
if (drive.IsReady && drive.Name == driveName)
{
return drive.TotalFreeSpace;
}
}
return -1;
}
public static bool CreateDummyFile(string filename, int length)
{
using (var fileStream = new FileStream(filename, FileMode.Create, FileAccess.Write, FileShare.None))
{
fileStream.SetLength(1024 * 1024 * length);
}
return true;
}
}
}