fso| drives Use the FileSystemObject (FSO) object model to work with drives and folders in a planned manner, just as they are handled interactively in Windows Explorer. You can copy and move folders, get information about drives and folders, and so on.
Get information about a drive
You can use the Drive object to obtain information about the various drives that are in kind or connected to the system over the network. Its properties can be used to obtain the following information content:
Total capacity of the drive, in bytes (TotalSize property)
How much free space is in the drive, in bytes (AvailableSpace or FreeSpace properties)
Which number was assigned to the drive (DriveLetter property)
What type of drive is it, such as removable, fixed, network, CD-ROM, or RAM disk (DriveType property)
Serial number of the drive (SerialNumber property)
File system types used by the drive, such as FAT, FAT32, NTFS, and so on (filesystem properties)
Whether the drive can be used (IsReady property)
Names of shares and/or volumes (ShareName and VolumeName properties)
Drive path or root folder (path and RootFolder properties)
Examples of usage of Drive objects
Use the Drive object to gather information about the drive. In the following code, there is no reference to the actual Drive object; instead, the Getdrive method is used to obtain a reference to an existing Drive object (in this case, DRV).
The following example demonstrates how to use the 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 spaces:" & FormatNumber (DRV). totalsize/1024, 0)
s = S & "Kb" & "<br>"
s = S & "Free Spaces:" & FormatNumber (DRV). freespace/1024, 0)
s = S & "Kb" & "<br>"
Response.Write S
End Sub
The following code demonstrates implementing the same functionality 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);
}
Working with folders
In the following table, you describe common folder tasks and how to execute them.
Task methods
Create a folder---Filesystemobject.createfolder
Delete a folder---folder.delete or filesystemobject.deletefolder
Move a folder---folder.move or filesystemobject.movefolder
Copy Folder---folder.copy or filesystemobject.copyfolder
Retrieves the name of a folder---folder.name
If the folder exists on the drive, find it. ---filesystemobject.folderexists
Get an instance of an existing Folder object---filesystemobject.getfolder
Locate the folder's parent folder name. Filesystemobject.getparentfoldername---
Locate the path to the system folder. Filesystemobject.getspecialfolder
The following example demonstrates how to use the folder and FileSystemObject objects in VBScript to manipulate folders and get information about them:
Sub Showfolderinfo ()
Dim FSO, FLDR, S
' Get an instance of FileSystemObject.
Set fso = CreateObject ("Scripting.FileSystemObject")
' Get the Drive object.
Set Fldr = fso. GetFolder ("C:")
' Print the name of the parent folder.
Response.Write "Parent folder name is:" & Fldr & "<br>"
' Print the drive name.
Response.Write "contained on drive" & Fldr. Drive & "<br>"
' Print the root file name.
If Fldr. IsRootFolder = True Then
Response.Write ' This is the root folder. ' & ' <br> ' <br> '
Else
Response.Write "This folder isn ' t a root folder." & "<br><br>"
End If
' Create a new folder with the FileSystemObject object.
Fso. CreateFolder ("C:\Bogus")
Response.Write "Created folder C:\Bogus" & "<br>"
' Print the basic name of the folder.
Response.Write "Basename =" & FSO. Getbasename ("C:\bogus") & "<br>"
' Delete the newly created folder.
Fso. DeleteFolder ("C:\Bogus")
Response.Write "Deleted folder C:\Bogus" & "<br>"
End Sub
The following example shows how to use the Folder and FileSystemObject objects in JScript:
function Showfolderinfo ()
{
var fso, fldr, S = "";
Get an instance of FileSystemObject.
FSO = new ActiveXObject ("Scripting.FileSystemObject");
Gets the Drive object.
Fldr = fso. GetFolder ("C:");
/