Javascript FileSystemObject (FSO) consists of DriveExists method that provides the functionality to check whether the specified drive exists at the given location or not. FSO DriveExists method returns the Boolean value i.e. true or false based on the existence of the specified drive. DriveExists method returns true if the drive exits and returns false if not. Javascript DriveExists method is very useful while creating or deleting the files or folders at client side coz if specified drive does not exist while mapping the path of the specified file or folder then it throws an error and stops the execution of rest of javascript code placed after that code line.
Syntax for Javascript FSO DriveExists Method
fso.DriveExists( driveSpec );
As shown above FSO DriveExists method accepts only one parameter as drive specification. It checks the specified drive and returns the Boolean value accordingly.
Example for FSO DriveExists Method
<script type="text/javascript">
// initialize ActiveXObject and create an object of Scripting.FileSystemObject.
var fso = new ActiveXObject("Scripting.FileSystemObject");
// if condition to check whether the specified drive exists or not.
if (fso.DriveExists("D")) {
document.write("Drive D: exists.");
}
else {
document.write("Drive D: does not exist.");
}
fso = null;
</script>
Continue to next tutorial: Javascript FSO FileExists Method to learn checking whether the specified file exists or not.