SoFunction
Updated on 2025-04-14

Handle drives and folders

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("")
Set drv = ((drvPath))
s = "Drive " & UCase(drvPath) & " - "
s = s & & "<br>"
s = s & "Total Space: " & FormatNumber( / 1024, 0)
s = s & " Kb" & "<br>"
s = s & "Free Space: " & FormatNumber( / 1024, 0)
s = s & " Kb" & "<br>"
s
End Sub

The following code shows the same functionality in JScript:
function ShowDriveInfo1(drvPath)
{
var fso, drv, s ="";
fso = new ActiveXObject("");
drv = ((drvPath));
s += "Drive " + ()+ " - ";
s += + "<br>";
s += "Total Space: " + / 1024;
s += " Kb" + "<br>";
s += "Free Space: " + / 1024;
s += " Kb" + "<br>";
(s);
}

Process folders
In the following table, ordinary folder tasks and methods of executing them are described.
Task Method
Create a folder.
Delete the folder. or
Move folders. or
Copy the folder. or
Search the name of the folder.
If the folder exists on the drive, find it.
Gets an instance of an existing Folder object.
Find the parent folder name of the folder.
Find the path to the system folder.


Please check the sample code to see how many methods and properties are used in FileSystemObject.

The following example shows how to use Folder and FileSystemObject objects in VBScript to manipulate folders and obtain information about them:


Sub ShowFolderInfo()
Dim fso, fldr, s
' Get an instance of FileSystemObject.
Set fso = CreateObject("")
' Get the Drive object.
Set fldr = ("c:")
' Print the parent folder name.
"Parent folder name is: " & fldr & "<br>"
' Print the driver name.
"Contained on drive " & & "<br>"
' Print the root file name.
If = True Then
"This is the root folder." & ""<br>"<br>"
Else
"This folder isn't a root folder." & "<br><br>"
End If
' Create a new folder with the FileSystemObject object.
("C:\Bogus")
"Created folder C:\Bogus" & "<br>"
' Print the basic name of the folder.
"Basename = " & ("c:\bogus") & "<br>"
' Delete the newly created folder.
("C:\Bogus")
"Deleted folder C:\Bogus" & "<br>"
End Sub

The following example shows how to use Folder and FileSystemObject objects in JScript:
function ShowFolderInfo()
{
var fso, fldr, s = "";
// Get an instance of FileSystemObject.
fso = new ActiveXObject("");
// Get the Drive object.
fldr = ("c:");
// Print the parent folder name.
("Parent folder name is: " + fldr + "<br>");
// Print the drive name.
("Contained on drive " + + "<br>");
// Print the root file name.
if ()
("This is the root folder.");
else
("This folder isn't a root folder.");
("<br><br>");
// Create a new folder with the FileSystemObject object.
("C:\\Bogus");
("Created folder C:\\Bogus" + "<br>");
// Print the basic name of the folder.
("Basename = " + ("c:\\bogus") + "<br>");
// Delete the newly created folder.
("C:\\Bogus");
("Deleted folder C:\\Bogus" + "<br>");
}