I recently wrote my first C# app that's goal it to take a drive letter and output a CSV list of some basic information. TOTALSPACE,FREESPACE,STATUS
.
I've been wondering If it would be possible to make this application even faster. Got any good suggestions?
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace drivespace
{
class Program
{
static void Main(string[] args)
{
//"PATHTOEXE\drivespace.exe" drive-C:
foreach (String arg in args)
{
String[] parts = arg.Split('-');
if (parts[0].Equals("drive"))
{
long toalspace = 0;
long freespace = 0;
string status = "NOTFOUND";
foreach (DriveInfo drive in DriveInfo.GetDrives())
{
if (drive.Name == parts[1] + ":\\")
{
if (drive.IsReady)
{
toalspace = drive.TotalSize;
freespace = drive.TotalFreeSpace;
status = "READY";
}
else
{
status = "NOTREADY";
}
break;
}
}
//TOTALSPACE,FREESPACE,STATUS
Console.WriteLine(toalspace.ToString() + "," + freespace.ToString() + ',' + status);
}
}
}
}
}
https://github.com/keverw/drivespace is the Github page, it might have some more useful info.
DriveInfo
is aclass
..... Possibly provide us with that? \$\endgroup\$DriveInfo
isn't built into c# \$\endgroup\$