Marine Corps Leadership Secrets - Part IIMy.Computer.FileSystem Shortcuts for VB.NET - Part IV

My.Computer.FileSystem Shortcuts for VB.NET - Part III

July 27th, 2007

My.Computer.FileSystem ShortcutsHere’s my next installment on the My.Computer.FileSystem Namespace. This article series takes a look at functions in this namespace and rate their usefulness as compared to related NET Framework functions.

GetDirectoryInfo
.
.
.
.
.
Our first stop today is GetDirectoryInfo:
.
.

Dim MyPathInfo As System.IO.DirectoryInfo = My.Computer.FileSystem.GetDirectoryInfo(MyPath)

.

This function returns a System.IO.DirectoryInfo object. It is exactly the same as this System.IO function:

Dim MyPathInfo As System.IO.DirectoryInfo = New System.IO.DirectoryInfo(MyPath)

.

Therefore, it doesn’t provide any extra value to the developer. I give it 2 out of 5.

GetDriveInfo

Next we have a related function, GetDriveInfo:

Dim MyDriveInfo As System.IO.DriveInfo = My.Computer.FileSystem.GetDriveInfo(DriveLetter)

.

As with GetDirectoryInfo, it’s almost an exact duplicate of a System.IO function:

Dim MyDriveInfo As System.IO.DriveInfo = New System.IO.DriveInfo(DriveLetter)

It is a redundant function so it only rates 2 out of 5 as well.

GetFileInfo

As seen here this is yet another duplicate of a System.IO Info function:

Dim MyFileInfo As System.IO.FileInfo = My.Computer.FileSystem.GetFileInfo(MyFile)

Dim MyFileInfo As System.IO.FileInfo = New System.IO.FileInfo(MyFile)

As such, it also gets a 2 out of 5.

GetName

This function parses a path/filename string and returns the base file name, with extension:

Dim BaseFileName As String = My.Computer.FileSystem.GetName(FilenameToParse)

This is a rather useful function since it relieves you of having to manage the string parsing yourself and takes care of spaces and extra periods in filenames, something that often gets overlooked in handmade path parsers. I’ll give this function a 4 out of 5.

GetParentPath

This function is the opposite number of GetName. It returns the path portion of the file/path name.

Dim ParentPath As String = My.Computer.FileSystem.GetParentPath(FilenameToParse)

Like its counterpart, its parser handles extra periods and spaces without a hitch. Bear in mind that it doesn’t add a trailing backslash onto the returned path name so don’t forget that when you’re concatinating a path/file string.

This function also rates a 4 out of 5

GetTempFileName

Our last function for today is GetTempFileName. This function creates a uniquely named temporary file and returns the path/filename for it.

Dim TmpFileName As String = My.Computer.FileSystem.GetTempFileName

Returns: C:\Documents and Settings\[username]\Local Settings\Temp\tmpB3.tmp

I had covered this function previously in my article 3 Quick Examples: Temp File, Topmost Form and Current User Name. The only hitch with the function is that it automatically uses the default temp folder. If you want to use your own folder, which I don’t really recommend, you’ll probably find it better to code this separately from this function.

I give this function a 4 out of 5.

I’ll be covering more functions from My.Computer.FileSystem soon. Please leave me a comment if your rating of these functions is different from mine or if I overlooked something.

Share This Article: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Reddit
  • StumbleUpon
  • Technorati
  • DotNetKicks
  • DZone

Entry Filed under: VB.NET Tutorials


Rate This Article:

Not That GoodCould Be BetterOKGoodGreat (2 votes, average: 5 out of 5)
Loading ... Loading ...

Leave a Comment

Required

Required, hidden

Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Trackback this post  |  Subscribe to the comments via RSS Feed


Visit Me At My New Site, Programming In C#

Most Popular Articles

Highest Rated Articles

Categories

Most Recent Articles

Feeds

 Subscribe in a reader

To subscribe by e-mail
Enter your address here

Delivered by FeedBurner

VB Opportunities

Archives