Javascript FileSystemObject (FSO) GetDriveName method provides the functionality to get the drive name of from the specified path of file or folder. GetDriveMethod does not take care of existence of specified file or folder; it just returns the associated drive name based on the specified path. FSO GetDriveName method returns the drive letter along with colon “:” symbol.
Syntax for Javascript FSO GetDriveName Method
fso.GetDriveName( Path );
FSO GetDriveName method accepts only one parameter as path for any file or folder from which this method extracts the drive name.
Example for FSO GetDriveName method
<script type="text/javascript">
// initialize ActiveXObject and create an object of Scripting.FileSystemObject.
var fso = new ActiveXObject("Scripting.FileSystemObject");
// returns the drive name from the specified path
var driveName = fso.GetDriveName("c:\\Temp\\myFolder\\file.txt");
document.write(driveName);
document.write("<br />");
fso = null;
// Output:
// c:
</script>
Continue to next tutorial: Javascript FSO GetExtensionName Method to learn how to get the file extension.