This repository has been archived by the owner on Aug 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
freespace.cs
58 lines (49 loc) · 1.97 KB
/
freespace.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
// Source: https://docs.microsoft.com/en-us/dotnet/api/system.io.driveinfo.availablefreespace
// To Compile:
// C:\Windows\Microsoft.NET\Framework\v2.0.50727\csc.exe /t:exe /out:freespace.exe freespace.cs
using System;
using System.IO;
class FreeSpace
{
public static void Main(string[] args)
{
try
{
if (args.Length > 0 && args[0] == "/?")
{
Console.WriteLine(@"Lists logical drives, including total and available free space. Mapped drives will only be shown when freespace.exe is run within the same session or with the same credentials used to map the drive.
USAGE:
freespace.exe [/?]");
return;
}
DriveInfo[] allDrives = DriveInfo.GetDrives();
foreach (DriveInfo d in allDrives)
{
Console.WriteLine("\nDrive {0}", d.Name);
Console.WriteLine(" Drive type: {0}", d.DriveType);
if (d.IsReady == true)
{
Console.WriteLine(" Volume label: {0}", d.VolumeLabel);
Console.WriteLine(" File system: {0}", d.DriveFormat);
Console.WriteLine(
" Available space to current user:{0, 22} bytes",
String.Format("{0:n0}", d.AvailableFreeSpace));
Console.WriteLine(
" Total available space: {0, 22} bytes",
String.Format("{0:n0}", d.TotalFreeSpace));
Console.WriteLine(
" Total size of drive: {0, 22} bytes ",
String.Format("{0:n0}", d.TotalSize));
}
}
}
catch (Exception e)
{
Console.Error.WriteLine("[-] ERROR: {0}", e.Message.Trim());
}
finally
{
Console.WriteLine("\nDONE");
}
}
}