473,395 Members | 1,647 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

New DIR function behaviour in VB.Net

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
Jul 21 '06 #1
1 10439
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
"Scott" <Sc***@discussions.microsoft.comwrote in message
news:EA**********************************@microsof t.com...
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


Jul 21 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: publictom | last post by:
I just happened to read item 47, "Control Flow", in Exceptional C++ by Herb Sutter (which is based on Guru of the Week 12), just after reading item 33, "Use Inlining Judiciously", in Effective C++...
8
by: Henk van Winkoop | last post by:
Hello, I debugged some html file and found this: ------------------------------------------------------------ <script language="JavaScript"> if ( some_statement ) { function MyFunction (...
75
by: Sweety | last post by:
hi, Is main function address is 657. its show in all compiler. try it & say why? bye,
18
by: Razvan | last post by:
Hi! What is the purpose of such a function ? int function(void)
2
by: Vaddina Prakash Rao | last post by:
Hi all .. I describe here a wierd behaviour .. i dont understand why ... This could be very stupid aswell .. so please bear me .. I have been writing a program to accept multiple parameters and...
7
by: Alfonso Morra | last post by:
How can this work ? I have the following declarations in a header: Header ========= typedef void (*VFPTR)(void) ; void FOO_Callback(void*, char*, char*, int, unsigned long, void*,void*);...
29
by: Vol | last post by:
I think 'atan' can get the angle but it is not the four quadrant angle. Is there any function that i can get the angle from -pi to pi? or I have to use some if ... else? I know in Matlab, we use...
18
by: ben.carbery | last post by:
Hi, I have just written a simple program to get me started in C that calculates the number of days since your birthdate. One thing that confuses me about the program (even though it works) is...
3
by: subramanian100in | last post by:
Kindly explain what is meant by behaviour of a function ? Does it mean what task the function performs - say for example finding the square root of a function Or does it mean how a function...
53
by: souporpower | last post by:
Hello All I am trying to activate a link using Jquery. Here is my code; <html> <head> <script type="text/javascript" src="../../resources/js/ jquery-1.2.6.js"</script> <script...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.