FIX: Dir Method of File-System Control Ignores vbNormal

ID: Q184889


The information in this article applies to:
  • Microsoft Windows CE Toolkit for Visual Basic 5.0, version 1.0


SYMPTOMS

When using the vbNormal attribute in the Dir method of the File System control, no files are returned.

This problem occurs whether any specified files are Normal (GetAttr = 0) or Archive (GetAttr = 32).

Under Visual Basic 5.0, files flagged as Archive (GetAttr returns 32) are returned if the attribute parameter is set to vbNormal.


CAUSE

The Dir method does not interpret the vbNormal attribute as expected.


RESOLUTION

To work around this behavior, omit the attribute parameter from the Dir method and use the GetAttr method to check the attribute value (0 for vbNormal or 32 for vbArchive) when the items are read in.


STATUS

Microsoft has confirmed this to be a problem in the Microsoft products listed at the beginning of this article.

This problem was corrected in Windows CE Toolkit for Visual Basic 6.0.


MORE INFORMATION

Steps to Reproduce Behavior

  1. Start a new Windows CE project in Visual Basic 5.0.


  2. Click OK to dismiss the Project Properties dialog box.


  3. On the Project menu, click Components.


  4. Select "Microsoft CE File System Control 1.0" and click OK.


  5. Place a ListBox, a ComboBox and a File-System control on Form1.


  6. Add the following code to the form:

    
          Private Sub Form_Load()
             Combo1.AddItem "none"
             Combo1.AddItem "0 - vbNormal"
             Combo1.AddItem "2 - vbHidden"
             Combo1.AddItem "4 - vbSystem"
             Combo1.AddItem "8 - vbVolume"
             Combo1.AddItem "16 - vbDirectory"
             Combo1.ListIndex = 0
             Combo1_Click
          End Sub
    
          Private Sub Combo1_Click()
             Dim curDir
             Dim curAttr
             Dim itemStr
             curDir = "\*.*"
             curAttr = ""
             itemStr = ""
             List1.Clear
             List1.AddItem "Attributes: " & Combo1.List(Combo1.ListIndex)
             Select Case Combo1.ListIndex
                Case 0 '"none"
                   itemStr = FileSystem1.Dir(curDir)
                Case 1 '"0 - vbNormal"
                   itemStr = FileSystem1.Dir(curDir, 0)
                Case 2 '"2 - vbHidden"
                   itemStr = FileSystem1.Dir(curDir, 2)
                Case 3 '"4 - vbSystem"
                   itemStr = FileSystem1.Dir(curDir, 4)
                Case 4 '"8 - vbVolume"
                   itemStr = FileSystem1.Dir(curDir, 8)
                Case 5 '"16 - vbDirectory"
                   itemStr = FileSystem1.Dir(curDir, 16)
             End Select
             While itemStr <> ""
                List1.AddItem itemStr & " - " & _
                   FileSystem1.GetAttr("\" & itemStr)
                itemStr = FileSystem1.Dir
             Wend
          End Sub 


  7. Run the project.


Notice that when "0 - vbNormal" is selected, no files are returned. This occurs whether the file has an attribute of Archive or Normal.

To work around the error in the sample code above, change the Case 1 code for the Select Case statement to read as follows:

Case 1 '"0 - vbNormal"
      itemStr = FileSystem1.Dir(curDir)
      While itemStr <> ""
         curAttr = FileSystem1.GetAttr("\" & itemStr)
         If curAttr = 0 Or curAttr = 32 Then
            List1.AddItem itemStr & " - " & curAttr
         End If
      itemStr = FileSystem1.Dir
      Wend
      Exit Sub 


REFERENCES

Books Online for Microsoft Windows CE Toolkit for Visual Basic 5.0

Additional query words: VBCE wce list combo vbce5 vbce6

Keywords : kbToolkit kbVBp kbVBp500 kbVBp600fix kbWinCE kbWinCE100bug kbGrpVB
Version : WINDOWS:1.0
Platform : WINDOWS
Issue type : kbbug


Last Reviewed: March 3, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.