New DIR function behaviour in VB.Net

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Scott

    #1

    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.D irectory)
    Do While strFolder ""
    If GetAttr(strBase & strFolder) = FileAttribute.D irectory And
    strFolder <"." Then
    If mintLevel 0 Or strFolder <".." Then
    itmFold = lsvFolders.List Items.Add(, , strFolder)
    If strFolder = ".." Then
    itmFold.Icon = "Up"
    Else
    itmFold.Icon = "Closed"
    End If
    End If
    End If
    'UPGRADE_WARNIN G: Dir has a new behavior. Click for more:
    'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?ke yword="vbup1041 "'
    strFolder = Dir()
    Loop
    =============== =============== =============== ==============
    Thanks Scott


  • SStory

    #2
    Re: New DIR function behaviour in VB.Net

    Dot net is must more elegant.
    I suggest dropping DIR and using the system.io.direc tory, 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" <Scott@discussi ons.microsoft.c omwrote in message
    news:EAEF66FD-291C-4D46-AA2B-1AAAD680CCD5@mi crosoft.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.D irectory)
    Do While strFolder ""
    If GetAttr(strBase & strFolder) = FileAttribute.D irectory And
    strFolder <"." Then
    If mintLevel 0 Or strFolder <".." Then
    itmFold = lsvFolders.List Items.Add(, , strFolder)
    If strFolder = ".." Then
    itmFold.Icon = "Up"
    Else
    itmFold.Icon = "Closed"
    End If
    End If
    End If
    'UPGRADE_WARNIN G: Dir has a new behavior. Click for more:
    'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?ke yword="vbup1041 "'
    strFolder = Dir()
    Loop
    =============== =============== =============== ==============
    Thanks Scott
    >
    >

    Comment

    Working...