đăng 20:34 27 thg 3, 2012 bởi Hai Yen
[
đã cập nhật 07:42 16 thg 9, 2014
]
With the FileSystemObject (FSO) object model, you can work with drives and folders programmatically just as you can in the Windows Explorer interactively. You can copy and move folders, get information about drives and folders, and perform other operations on drives and folders.Getting Information About Drives
The Drive Object enables you to obtain information about the various drives attached to a system, either physically or over a network. The following table shows the information that you can obtain by using its properties. For more information, see FileSystemObject Sample Code. Example of Using the Drive ObjectUse the Drive object to gather information about a drive. The following example demonstrates how to use the Drive object. In this example, the GetDrive Method method obtains a reference to an existing Drive object (in this case, drv). Sub ShowDriveInfo(path) Dim fso, drv, bytesPerGB, freeGB, totalGB, s
s = "" bytesPerGB = 1024 * 1024 * 1024
Set fso = CreateObject("Scripting.FileSystemObject") Set drv = fso.GetDrive(fso.GetDriveName(path))
s = s & drv.Path & " - "
if drv.IsReady Then freeGB = drv.FreeSpace / bytesPerGB totalGB = drv.TotalSize / bytesPerGB
s = s & FormatNumber(freeGB, 3) + " GB free of " s = s & FormatNumber(totalGB, 3) + " GB" Else s = s & "Not Ready" End If s = s & "<br />"
document.write (s) End Sub
This language is not supported or no code example is available.
Common folder tasks and the methods for performing them are described in the following table. For more information, see FileSystemObject Sample Code. The following example demonstrates how to use the Folder Object and FileSystemObject Object to work with folders and obtain information about them. Sub ShowFolderInfo() Dim fso, fldr, s, newLine, newFolderName newLine = "<br />"
Set fso = CreateObject("Scripting.FileSystemObject") Set fldr = fso.GetFolder("c:\")
s = s & "Folder: " + fldr & newLine s = s & "Drive: " + fldr.Drive & newLine
If fldr.IsRootFolder Then s = s & "Root Folder" Else s = s & "Parent Folder: " & fldr.ParentFolder End If s = s & newLine
' Create and delete a folder. newFolderName = "C:\TempFolder1" fso.CreateFolder(newFolderName) s = s & "Base Name of Added Folder: " & fso.GetBaseName(newFolderName) fso.DeleteFolder(newFolderName)
s = s & newLine document.write(s) End Sub
|
|