New DIR function behaviour in VB.Net

G

Guest

Apparently VB.Net has a new behaviour for the DIR function and I quote: -
==================================================================================================
In Visual Basic 6.0, the Dir function was used to return the name of a
file, folder, or directory. The "." and ".." strings could be used in the
path argument to represent the current directory or the encompassing
directory, respectively.

In Visual Basic .NET, the Dir function is essentially the same, but the
"." and ".." syntax has a different behavior.

What to do next

Code that returned files or directories was often written with the
assumption that the "." and ".." would be returned as the first two entries;
this
is no longer true in Visual Basic .NET. Because of the difference in
behavior, the upgraded code may not return the first two files or
directories.
=================================================================================================

The code we have looks for the . or .. and will change the icon and also
provide the facility to go back to the upper level. Does anyone know how we
can alter the code in .Net to allow for the new behaviour.

Our code is as follows: -

strFolder = Dir(strBase & "*.*", FileAttribute.Directory)
Do While strFolder > ""
If GetAttr(strBase & strFolder) = FileAttribute.Directory And
strFolder <> "." Then
If mintLevel > 0 Or strFolder <> ".." Then
itmFold = lsvFolders.ListItems.Add(, , strFolder)
If strFolder = ".." Then
itmFold.Icon = "Up"
Else
itmFold.Icon = "Closed"
End If
End If
End If
'UPGRADE_WARNING: Dir has a new behavior. Click for more:
'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1041"'
strFolder = Dir()
Loop
===========================================================
Thanks Scott
 
S

SStory

Dot net is must more elegant.
I suggest dropping DIR and using the system.io.directory, directoryinfo,
file, fileinfo classes.

They make things so simple.

You can create a file/folder ListView item that inherits from ListView item,
if you want to have something that will display in the listview and still
keep the files info.

There is a method to search the directory based on search path, it returns
all files. GetDirectories returns all sub directories so there is really no
need for DIR anymore.

Most anything you can think of has already been written in the framework if
you just look around a bit. If you go with vb 2005, the My namespace makes
it even simpler.

Rewriting is the way to go.

HTH,

Shane
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top