|
Microsoft Scripting Runtime DLL
Part:
1
2
3
4
(Continued from previous part...)
- "Drives": Property to return a read-only collection of "Drive" objects representing all drives
in the current file system.
- "GetDrive(drivePath)": Method to return a Drive object of the specified drive path
(driver letter with ':').
- "GetFolder(folderPath)": Method to return a Folder object of the specified folder
path name.
- "GetFile(filePath)": Method to return a File object of the specified file
path name.
- "CreateTextFile(pathname,[override[,unicode]])": Method to create a new text file
and return a TextStream object connected to the new file.
"override=true|false" specifies if the new file can override an existing file.
"unicode=false|true" specifies if the new should written with unicode encoding.
- "OpenTextFile(pathname[,io_mode[,create[,tristate]]])": Method to open a file and
returns a TextStream object connected to the file. "create=false|true" specifies
that if a new can be created when the specified file does not exists.
io_mode(=1|2|8: ForReading|ForWriting|ForAppending) specifies how the file should be openned.
tristate(=-2|-1|0: TristateUserDefault|TristateTrue|TristateFalse) speficies if the file should
be open as Unicode or not.
- "CopyFile(from_pathname, to_pathname)": Method to copy a file specified by the
from_pathname to the to_pathname.
- "DeleteFile()": Method to delete a file.
- "MoveFile()": Method to move a file.
- "FileExists()": Method to check if a file exists.
- "CreateFolder": Method to create a folder.
- "CopyFolder()": Method to copy a folder.
- "DeleteFolder()": Method to delete a folder.
- "MoveFolder()": Method to move a folder.
- "FolderExists()": Method to check if a folder exists.
- "DriveExists": Method to check if a drive exists.
Below is a simple ASP page to how to create a folder and copy a file by using
the FileSystemObject class.
<script language="vbscript" runat="server">
' file_sytem.asp
' Copyright (c) 1999 by Dr. Herong Yang
' This program shows how to use the FileSystemObject class.
'
response.write("<html><body>")
response.write("<b>Tests on the FileSystemObject class</b>:<br/>")
' Getting the FileSystemObject object
set fs = CreateObject("Scripting.FileSystemObject")
if fs.FolderExists("c:\temp\backup") then
fs.DeleteFolder("c:\temp\backup")
end if
set d = fs.CreateFolder("c:\temp\backup")
fs.CopyFile "c:\inetpub\wwwroot\file_system.asp", _
"c:\temp\backup\file_system.asp"
response.write("File copied: c:\temp\backup\file_system.asp<br/>")
response.write("</body></html>")
</script>
Output:
Tests on the FileSystemObject class:
File copied: c:\temp\backup\file_system.asp
It's interesting to note that:
- VBScript statements can be continued to the next line with "_" as the end character.
- File name must be specified in the to_pathname for the CopyFile() method.
"Drive" Class
"Drive": A class representing a drive of the file system. It offers the following
methods and properties:
- "DriveLetter": Property to return the drive letter.
- "DriveType": Property to return the drive type, 0 for unknown, 1 for removable,
2 for fixed, 3 for network, 4 for CD-ROM, and 5 for RAM disk.
- "FileSystem": Property to return the file organization type of the drive.
- "IsReady": Property to return the status of the drive.
- "Path": Property to return the path name of the drive.
- "SerialNumber": Property to return the serial number of the drive.
- "ShareName": Property to return the share name of the drive.
- "VolumeName" Property to return the volume name of the drive.
- "TotalSize": Property to return the total space in units of byte.
- "AvailableSpace": Property to return the free space on the drive in units of byte.
- "FreeSpace": Property to return the free space on the drive in units of byte.
What's the difference between FreeSpace and AvailableSpace?
- "RootFolder": Property to return a "Folder" object representing the root directory
of the drive.
Here is a sample ASP page to show the above properties:
<script language="vbscript" runat="server">
' drive_test.asp
' Copyright (c) 1999 by Dr. Herong Yang
' This program shows how to use the Drive class.
'
response.write("<html><body>")
response.write("<b>Tests on the Drive class</b>:<br/>")
' Creating a FileSystemObject object
set fs = CreateObject("Scripting.FileSystemObject")
set ds = fs.Drives
response.write("List of drives:<br/>")
' Display all drives and their properties
for each d in ds
response.write("Drive Letter = " & d.DriveLetter & "<br/>")
response.write("Drive Type = " & d.DriveType & "<br/>")
response.write("Is Ready = " & d.IsReady & "<br/>")
response.write("Path = " & d.Path & "<br/>")
response.write("Share Name = " & d.ShareName & "<br/>")
if d.IsReady then
response.write("File System = " & d.FileSystem & "<br/>")
response.write("Serial Number = " & d.SerialNumber & "<br/>")
response.write("Volume Name = " & d.VolumeName & "<br/>")
response.write("Total Size = " & d.TotalSize & "<br/>")
response.write("Free Space = " & d.FreeSpace & "<br/>")
end if
next
response.write("</body></html>")
</script>
Output:
Tests on the Drive class:
List of drives:
Drive Letter = C
Drive Type = 2
Is Ready = True
Path = C:
Share Name =
File System = NTFS
Serial Number = 1545214583
Volume Name = New Volume
Total Size = 9697603584
Free Space = 4838227968
Drive Letter = D
Drive Type = 4
Is Ready = False
Path = D:
Share Name =
Note that:
- Drive "D:" is my CD-ROM, which is not ready.
- "fs.Drives" is not really returning an array. It is returning a kind of collection object.
I will find it out later.
(Continued on next part...)
Part:
1
2
3
4
|