Results 1 to 6 of 6

Thread: Problem using GetAttr [SOLVED]

  1. #1

    Thread Starter
    Fanatic Member hothead's Avatar
    Join Date
    Mar 2002
    Location
    Missouri
    Posts
    692

    Problem using GetAttr [SOLVED]

    This is rather confusing to me, and I would like someone to shed some light on the subject.

    I am using GetAttr to get the attributes of each item in a listview. For some reason, it doesn't see the Program Files directory as a directory, but as a 0-byte file instead.

    I looked at its attributes in Explorer, and I found that its read-only attribute had been set. Thinking that might be what was causing the problem, I turned it off and tried my program again. Same result. It still sees the Program Files directory as a 0-byte file. Could I have just found a known bug in the function, or is that actually the way it's supposed to work?

    Is there any way I can look at the file's type rather than its attributes? Explorer sees its type fine as a file folder, so that might be the approach I will take.
    Last edited by hothead; Sep 16th, 2003 at 05:44 PM.

  2. #2

  3. #3
    Frenzied Member KayJay's Avatar
    Join Date
    Jul 2001
    Location
    Chennai
    Posts
    1,849
    Bitwise Add the "System" constant
    VB Code:
    1. Private Sub Command1_Click()
    2. Dim strDir As String
    3. strDir = "D:\Program Files"
    4. 'If GetAttr(strDir) = vbDirectory Then
    5. If GetAttr(strDir) = vbDirectory Or vbSystem Then
    6.     MsgBox "Ok"
    7. Else
    8.     MsgBox GetAttr(strDir)
    9. End If
    10. End Sub

    HTH

    Regards

    Kaushik Janardhanan

    "Brothers, you asked for it."
    ...Francisco Domingo Carlos Andres Sebastian D'Anconia

  4. #4
    Frenzied Member KayJay's Avatar
    Join Date
    Jul 2001
    Location
    Chennai
    Posts
    1,849
    For some reason the "Archive" attribute &H20 gets appended as a string "20" to the result, not "added", hence the 2097.

    Ideas anyone?


    "Brothers, you asked for it."
    ...Francisco Domingo Carlos Andres Sebastian D'Anconia

  5. #5

    Thread Starter
    Fanatic Member hothead's Avatar
    Join Date
    Mar 2002
    Location
    Missouri
    Posts
    692
    I shall use this information to fall back on if need be. Thanks Marty.

    KayJay, I found some interesting info. I got a value of 17 from the Program Files directory using GetAttr. Now I remember from using chmod in Linux (I have Mandrake 9.0) that adding the values of two attributes will give you a strange result like that. Using my VB book, I found the following information:

    vbDirectory = 16 using GetAttr
    vbReadOnly = 1 using GetAttr

    Then I added the two values together.

    16 + 1 = 17

    Next, I put in the following code, which should have fixed this problem if I remember my Linux correctly:

    VB Code:
    1. For i = 1 To lvwDirListings.ListItems.Count
    2.         If Not lvwDirListings.ListItems(i) = ".." And GetAttr(Dir1.Path & "\" & lvwDirListings.ListItems(i)) = vbDirectory Or GetAttr(Dir1.Path & "\" & lvwDirListings.ListItems(i)) = vbDirectory And vbReadOnly Then
    3.             lvwDirListings.ListItems(i).SubItems(1) = "<DIR>"
    4.             lvwDirListings.ListItems(i).SubItems(2) = FileDateTime(Dir1.Path & lvwDirListings.ListItems(i))
    5.         End If
    6.     Next i

    However, this still doesn't fix it. (?)

    I have even gone as far as removing the Read-Only attribute, however Explorer turns it back on. Then I tried this:

    VB Code:
    1. If Not lvwDirListings.ListItems(i) = ".." And GetAttr(Dir1.Path & "\" & lvwDirListings.ListItems(i)) = vbDirectory Or lvwDirListings.ListItems(i) = "Program Files" Then

    It still will not work.
    Last edited by hothead; Sep 16th, 2003 at 05:28 PM.

  6. #6

    Thread Starter
    Fanatic Member hothead's Avatar
    Join Date
    Mar 2002
    Location
    Missouri
    Posts
    692
    I fixed it. Thanks very much.
    Last edited by hothead; Sep 16th, 2003 at 05:43 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width