complete-reference-vb_net_49
complete-reference-vb_net_49
• Drive Lets you extract information about drives attached to the local computer or a remote computer
on the network. With it, you can determine how much space is available on the drive, what share
names it has, and so on. The Drive object lets you access other devices as well, such as a CD−ROM
drive, a RAM disk, and a DVD.
• Drives Exposes Count and Item properties
• Folder Lets you create, delete, or move folders. It also supports the ability to research folder names,
paths, and more
• File Lets you create, delete, or move files. It also supports the ability to research filenames, paths,
and other information.
• TextStream Lets you read and write text files
To use the FSO in your application, you need to create a reference to the Scripting type library (Scrrun.dll) in
which it resides. This is a COM object that typically lives in the operating system's folders (such as
C:\Winnt\System32). But you can access and reference it in your project by adding the reference to it from the
References Folder, Add Reference option, or from your project's menus. The low−down on adding interop
references can be found in Chapters 3 and 4.
Click the COM tab in the Add Reference dialog box and scroll down to the item that reads Microsoft
Scripting Runtime. Double−click the item to select it and click OK. Presto, an interop wrapper is spun around
this legacy DLL, and you can start using it (just don't go "interopping" every legacy DLL you've been using in
your VB apps for the past ten years, or your apps will start crawling to a halt in no time).
At the top of your class that you are going to use to code against the FSO add an Imports statement and point
it to the Scripting namespace created in the interop wrapper. You'll see it the second you type Imports. You
can now start using the facilities in this namespace immediately.
Or you can call old faithful, the CreateObject method, and pass the FQNS (the legacy type library and the
object it encapsulates) to the FSO as an argument. This affects the bridge as well. The latter option is
demonstrated as follows:
Once you have referenced the Scripting DLL, you can browse the interop.Scripting assembly in the Object
Browser. You will notice that most of the objects, classes, and methods do not offer anything special or
different from the native File and FileInfo classes (we will also be covering .NET's Directory and Path
classes shortly, so sit tight). However, the Drive and Drives classes are worth looking at.
Drive provides you with a neat collection of methods for accessing volume information, available space, drive
letters, share names, and so on. What I like about Drive is its ability to access drive information on both local
computers and remote computers on the network. The properties listed in Table 15−19 provide disk and
volume information.
Table 15−19: The Properties of the Drive Class in the File System Object
533