Using FileSystemObject (FSO) object mode, drives and folders can be processed in a planned manner, just like they are handled interactively in Windows Explorer. You can copy and move folders, get information about drives and folders, and more.
Get information about the drive
Drive objects can be used to obtain information about various drives that are physically connected to the system or over a network. Its properties can be used to obtain the following information:
Total capacity of the drive, in bytes (TotalSize property)
What is the available space for the drive, in bytes (AvailableSpace or FreeSpace attribute)
Which number is assigned to the drive (DriveLetter property)
What is the type of drive, such as removable, fixed, networked, CD-ROM or RAM disk (DriveType property)
The serial number of the drive (SerialNumber property)
The file system type used by the drive, such as FAT, FAT32, NTFS, etc. (FileSystem property)
Is the drive usable (IsReady property)
Share and/or volume name (ShareName and VolumeName properties)
The path or root folder of the drive (Path and RootFolder properties)
Please examine the sample code to understand how to use these properties in FileSystemObject.
Drive object usage example
Use Drive objects to collect information about the drive. In the following code, there is no reference to the actual Drive object; instead, use the GetDrive method to get a reference to the existing Drive object (in this example, drv).
The following example shows how to use a Drive object in VBScript:
Sub ShowDriveInfo(drvPath)
Dim fso, drv, s
Set fso = CreateObject(Scripting.FileSystemObject)
Set drv = fso.GetDrive(fso.GetDriveName(drvPath))
s = Drive & UCase(drvPath) & -
s = s & drv.VolumeName & <br>
s = s & Total Space: & FormatNumber(drv.TotalSize / 1024, 0)
s = s & Kb & <br>
s = s & Free Space: & FormatNumber(drv.FreeSpace / 1024, 0)
s = s & Kb & <br>
Response.Write s
End Sub
The following code shows that the same function is implemented in JScript:
function ShowDriveInfo1(drvPath)
{
var fso, drv, s =;
fso = new ActiveXObject(Scripting.FileSystemObject);
drv = fso.GetDrive(fso.GetDriveName(drvPath));
s += Drive + drvPath.toUpperCase()+ - ;
s += drv.VolumeName + <br>;
s += Total Space: + drv.TotalSize / 1024;
s += Kb + <br>;
s += Free Space: + drv.FreeSpace / 1024;
s += Kb + <br>;
Response.Write(s);
}
Process folders
In the following table, ordinary folder tasks and methods of executing them are described.
Task method
Create a folder. FileSystemObject.CreateFolder
Delete the folder. Folder.Delete or FileSystemObject.DeleteFolder