/******************************************************************************
 *  Author: Chris West
 * Purpose: Display information about all of the drives on the PC.
 *****************************************************************************/
fso = new ActiveXObject("Scripting.FileSystemObject");
drives = fso.Drives;

// Lists the information for each available drive in msg.
msg = "";
for(e = new Enumerator(drives); !e.atEnd(); e.moveNext())
{
	drive = e.item();
	
	// Gets the name of the drive.
	if(drive.IsReady)
	{
		name = new Array();
		if(drive.VolumeName.length > 0)
			name.push(drive.VolumeName);
		if(drive.ShareName.length > 0)
			name.push(drive.ShareName);
		if(name.length > 0)
			msg += name.join(" - ") + " ";
	}
	
	// Gets the drive letter and type.
	msg += "(" + drive.DriveLetter + ":) " + getDriveType(drive.DriveType);
	
	// Gets the amount of free space and total space.
	if(drive.IsReady)
	{
		msg += "\n- " + fmt(drive.AvailableSpace) + " bytes of free space";
		msg += "\n- " + fmt(drive.TotalSize) + " bytes of total space";
	}
	msg += "\n\n";
}

// Displays the information for each available drive to the user.
WScript.Echo(msg.replace(/\n\n$/, ""));

// Returns the number that was passed in with commas in the appropriate places.
function fmt(num)
{
	return ("" + num).split("").reverse().join("").replace(/(\d\d\d)(?=\d)/g, "$1,")
		.split("").reverse().join("");
}

// Returns the string representation for the passed in drive type.
function getDriveType(driveType)
{
	switch(drive.DriveType)
	{
		case 0:	return "Unknown type of drive";
		case 1:	return "Removable drive";
		case 2:	return "Fixed drive";
		case 3:	return "Network drive";
		case 4:	return "CD-ROM drive";
		case 5:	return "RAM Disk";
	}
}