0% found this document useful (0 votes)
5 views

complete-reference-vb_net_48

Uploaded by

khalid
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

complete-reference-vb_net_48

Uploaded by

khalid
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Using the Classic File System Object

Name Overridden (p) Retrieves the name of this DirectoryInfo instance


Parent (p) Retrieves the parent directory of a specified subdirectory
Root (p) Retrieves the root portion of a path
Create Creates a directory
CreateSubdirectory Creates a subdirectory or subdirectories on the given path. The path can
be relative to this instance
Delete Deletes the resource directory and its contents from a path
GetDirectories Retrieves the subdirectories of the current directory
GetFiles Retrieves a file list from the current directory
GetFileSystemInfos Retrieves an array of strongly typed FileSystemInfo objects
MoveTo Moves a directory and its contents to a new path
Refresh Refreshes the state of the object
Instantiate a DirectoryInfo object passing in the directory path string (pName) to the method as follows:

Dim dirinfo As New DirectoryInfo("pName")

You can then code against the object, as demonstrated in the following example, which maintains a reference
to a DirectoryInfo object for folder management:

Dim dirifo As New DirectoryInfo("pName")


If dirinfo.Exists = False Then
'create the directory
dirinfo.Create()
End If

Creating a file and opening it are also quite simple with the DirectoryInfo class. Here is an example:

Dim folders As New DirectoryInfo("C:\indexworks")


folders.CreateSubdirectory("noisefiles")

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.

Using the Classic File System Object

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

You might also like