In Javascript, Drive object returned by the GetDrive method of FileSystemObject (FSO) provides the access to RootFolder property. This RootFolder property of Drive object returns the uppercase Letter followed by colon symbol “:” and backward slash “\” at the end that represents the root path of the specified drive. You can identify the drive of the client’s PC through this RootFolder property of Drive object. GetDrive method accepts the English alphabet representing drives of computer system for example A, C, D or E according to the number of drives found on client’s PC whose RootFolder path you want to retrieve. RootFolder property returns the UNC shared name of the drive for the specified shared network drive.
Example of Javascript Drive Object RootFolder Property
<script type="text/javascript">
// initialize ActiveXObject and create an object of Scripting.FileSystemObject.
var fso = new ActiveXObject("Scripting.FileSystemObject");
// Drive object reference set to driveObj variable
var driveObj = fso.GetDrive("C");
// returns the folder name representing the root folder of specified drive
document.write("<b>Root Folder Path :</b> " + driveObj.RootFolder);
document.write("<br />");
document.write("<b>Root Folder Path :</b> "
+ fso.GetDrive("\\\\my-PC\\E").RootFolder);
// Output:
// Root Folder Path : C:\
// Root Folder Path : \\my-PC\e\
</script>
Continue to next tutorial: Javascript FSO Drive Object SerialNumber property to learn how to get the serial number of the drive.