JavaScript Tutorial/MS JScript/Drive
Содержание
Drive
File System Objects (FSO) allow you to work with folders and files.
A Drive object is created using the GetDrive() method of the file system object.
Properties Associated with Drive Object
Item Description AvailableSpace Returns amount of space available to user on the specified drive or shared network DriveLetter Returns drive letter of a physical local drive or a shared network DriveType Returns value indicating the type of the specified drive FileSystem Returns type of file system in use for the specified drive FreeSpace Returns amount of free space available to user on the specified drive or shared network IsReady Returns status the specified drive Path Returns path for a specified file, folder, or drive RootFolder Returns a Folder object representing the root folder of a specified drive SerialNumber Returns decimal serial number used to uniquely identify a disk volume ShareName Returns shared network"s name for a specified drive TotalSize Returns total space of a drive or shared network VolumeName Sets or returns the volume name of the specified drive
<html>
<script language="JScript">
<!--
var drivePath = "C:";
var fileSysObj = new ActiveXObject("Scripting.FileSystemObject");
var drive = fileSysObj.GetDrive(fileSysObj.GetDriveName(drivePath));
-->
</script>
</html>
Drive.AvaliableSpace
Syntax
driveobject.AvaliableSpace
Drive.DriveLetter
The DriveLetter property contains the drive letter of the local drive or a shared network.
<html>
<script language="JScript">
<!--
var drivePath = "C:";
var fileSysObj = new ActiveXObject("Scripting.FileSystemObject");
var drive = fileSysObj.GetDrive(fileSysObj.GetDriveName(drivePath));
document.write("The driver letter for ",drivePath," is ",drive.DriveLetter);
-->
</script>
</html>
Drive.DriveType
The DriveType property contains a numeric value indicating type of the specified drive.
Drive Type Value Definitions
Value Description 0 Unknown 1 Removable 2 Fixed 3 Network 4 CD-ROM 5 RAM Disk
<html>
<script language="JScript">
<!--
var drivePath = "C:";
var fileSysObj = new ActiveXObject("Scripting.FileSystemObject");
var drive = fileSysObj.GetDrive(fileSysObj.GetDriveName(drivePath));
document.write("The drive type for ",drivePath," is ",drive.DriveType);
-->
</script>
</html>
Drive.FileSystem
The FileSystem property contains the type of file system used by the specified drive.
<html>
<script language="JScript">
<!--
var drivePath = "C:";
var fileSysObj = new ActiveXObject("Scripting.FileSystemObject");
var drive = fileSysObj.GetDrive(fileSysObj.GetDriveName(drivePath));
document.write("Drive ",drivePath," uses the ");
document.write(drive.FileSystem," file system.");
-->
</script>
</html>
Drive.FreeSpace
The FreeSpace property contains the amount of free space available.
<html>
<script language="JScript">
<!--
var drivePath = "C:";
var fileSysObj = new ActiveXObject("Scripting.FileSystemObject");
var drive = fileSysObj.GetDrive(fileSysObj.GetDriveName(drivePath));
document.write("Drive ",drivePath," has ",drive.FreeSpace," free space.");
-->
</script>
</html>
Drive.IsReady
If the drive is ready, true is returned, otherwise false is returned.
<html>
<script language="JScript">
<!--
var drivePath = "A:";
var drive = fileSysObj.GetDrive(fileSysObj.GetDriveName(drivePath));
if(drive.IsReady)
document.write("Drive ",drivePath," is ready.");
else
document.write("Drive ",drivePath," is NOT ready.");
-->
</script>
</html>
Drive.Path
The Path property contains the path of the specified file, folder, or drive.
<html>
<script language="JScript">
<!--
var drivePath = "C:";
var drive = fileSysObj.GetDrive(fileSysObj.GetDriveName(drivePath));
document.write("The path of drive C is ",drive.Path);
-->
</script>
</html>
Drive.RootFolder
The RootFolder property contains a Folder object that represents the root folder of the specified drive.
<html>
<script language="JScript">
<!--
function getCRootFolder() {
var drivePath = "C:";
var fileSysObj = new ActiveXObject("Scripting.FileSystemObject");
var drive = fileSysObj.GetDrive(fileSysObj.GetDriveName(drivePath));
return(drive.RootFolder);
}
-->
</script>
</html>
Drive.SerialNumber
The SerialNumber property contains the decimal serial number that uniquely identifies the specified disk volume.
<html>
<script language="JScript">
<!--
var drivePath = "C:";
var fileSysObj = new ActiveXObject("Scripting.FileSystemObject");
var drive = fileSysObj.GetDrive(fileSysObj.GetDriveName(drivePath));
document.write("Drive serial number is ",drive.SerialNumber);
-->
</script>
</html>
The ShareName property contains the network share name for the specified drive.
<html>
<script language="JScript">
<!--
var drivePath = "C:";
var fileSysObj = new ActiveXObject("Scripting.FileSystemObject");
var drive = fileSysObj.GetDrive(fileSysObj.GetDriveName(drivePath));
document.write(drive.ShareName);
-->
</script>
</html>
Drive.TotalSize
The TotalSize property returns the total size of the specified drive in bytes.
<html>
<script language="JScript">
<!--
var drivePath = "C:";
var fileSysObj = new ActiveXObject("Scripting.FileSystemObject");
var drive = fileSysObj.GetDrive(fileSysObj.GetDriveName(drivePath));
document.write("Drive ",drivePath," is ",drive.TotalSize," bytes.");
-->
</script>
</html>
Drive.VolumeName
Syntax
driveobject.VolumeName
driveobject.VolumeName = newVolumeName