complete-reference-vb_net_48
complete-reference-vb_net_48
You can then code against the object, as demonstrated in the following example, which maintains a reference
to a DirectoryInfo object for folder management:
Creating a file and opening it are also quite simple with the DirectoryInfo class. Here is an example:
Notice in the above example the CreateSubdirectory method only needs the name of the subdirectory. It will
throw an exception if you try to pass it path information.
The .NET Framework can wrap the classic File System Object (FSO) that many VB programmers are familiar
with. Bringing the FSO into .NET is a process that happens in less than ten mouse clicks, so the only
difficulty you may have in using it is deciding if you want to or have to. If you know your way around the
FSO model, you can continue to program against it, because the interop layer that wraps this legacy object
provides seamless access to the original objects in its COM DLL (the Microsoft Scripting Runtime). If this
support helps you with migration or porting, then you need to consider it until you are ready to adopt the
FileInfo and DirectoryInfo classes.
If, however, you do not care for the FSO or are not moving code from VB to Visual Basic .NET, then stick
with the "native" classes that don't need the additional overhead of the interop layers (the FSO is still very
fast, even in .NET).
For those of you who do not know about the FSO object model, it encapsulates the following objects:
532