|
-
Sep 15th, 2003, 07:52 PM
#1
Thread Starter
Fanatic Member
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.
-
Sep 15th, 2003, 08:59 PM
#2
Have you searched the forums for GetAttr? I did and found this post. If that doesn't help, some of the others might.
-
Sep 16th, 2003, 03:56 AM
#3
Frenzied Member
Bitwise Add the "System" constant
VB Code:
Private Sub Command1_Click()
Dim strDir As String
strDir = "D:\Program Files"
'If GetAttr(strDir) = vbDirectory Then
If GetAttr(strDir) = vbDirectory Or vbSystem Then
MsgBox "Ok"
Else
MsgBox GetAttr(strDir)
End If
End Sub
HTH
Regards
Kaushik Janardhanan
"Brothers, you asked for it."
...Francisco Domingo Carlos Andres Sebastian D'Anconia
-
Sep 16th, 2003, 04:06 AM
#4
Frenzied Member
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
-
Sep 16th, 2003, 05:21 PM
#5
Thread Starter
Fanatic Member
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:
For i = 1 To lvwDirListings.ListItems.Count
If Not lvwDirListings.ListItems(i) = ".." And GetAttr(Dir1.Path & "\" & lvwDirListings.ListItems(i)) = vbDirectory Or GetAttr(Dir1.Path & "\" & lvwDirListings.ListItems(i)) = vbDirectory And vbReadOnly Then
lvwDirListings.ListItems(i).SubItems(1) = "<DIR>"
lvwDirListings.ListItems(i).SubItems(2) = FileDateTime(Dir1.Path & lvwDirListings.ListItems(i))
End If
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:
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.
-
Sep 16th, 2003, 05:32 PM
#6
Thread Starter
Fanatic Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|