Solved

Get Attributes

Posted on 2000-04-13
14
225 Views
Last Modified: 2013-11-19
Hi,
I need help with the Getattr function.
just say i have two listboxes.
One stores Directories and the other one stores Files.
If i have an array with a mixture of folders and files and i want to sort them........................
Take a look at this code.

List1.AddItem "Directories"
List2.AddItem "Files"
For X = 0 to UBound(Mixture)
    If GetAttr(Mixture(X)) = VbDirectory
 Then
    List1.AddItem Mixture(X)
Else
    List2.AddItem Mixture(X)
EndIf
'End Of Codee.

Well i might have made a mistake with the code except as you can see if it is a directory it adds puts the item into List1 if it is a file it adds puts the item into List2.
Well the problem is in the GetAttr Function.
Just say Mixture() Which contains file and folder names has a folder name called "C:\Windows\Fonts" which is a system directory or virtual directory or whatever you want to call it.
The code will add "C:\Windows\Fonts" in the Files Section (List2) because the GetAttr fnction doesn't recognize C:\WIndows\Fonts as a normal directory.

How could I alter the code so that it can also recognize hidden and system directories.

You don't have to use the GetAttr Function.
If it is easier use an API.
Doesn't matter what method you use.
Youcan see what i want so just create code that works...
Thanks in advance
0
Comment
Question by:adam8
  • 5
  • 5
  • 2
  • +1
14 Comments
 
LVL 1

Author Comment

by:adam8
ID: 2714811
Adjusted points from 51 to 100
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2714823
how bout we just reverse it  =)

For X = 0 to UBound(Mixture)
    If GetAttr(Mixture(X)) <> VbDirectory
 Then
    List2.AddItem Mixture(X)
Else
    List1.AddItem Mixture(X)
EndIf
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2714827
geez never mind..i'm not thinking

but along those lines, test to see if its a file (either read only, hidden, etc)  if its none of those it must be a folder yes?
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 28

Expert Comment

by:Ark
ID: 2714859
Hi

List1.AddItem "Directories"
List2.AddItem "Files"
For X = 0 to UBound(Mixture)
    If GetAttr(Mixture(X) and vbDirectory) = VbDirectory
 Then
    List1.AddItem Mixture(X)
Else
    List2.AddItem Mixture(X)
EndIf

I've already checked - works with All directories (system, hidden, normal, system + hidden etc)
Cheers
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2714877
If GetAttr(Mixture(X) and vbDirectory) = VbDirectory
 

??????

Ark you lost me   =/
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2714903
how bout this:

Dim strExt As String
For X = 0 to UBound(Mixture)
    strExt = Right(Mixture(X),4)
    If InStr(1, strExt, ".")
 Then
    List2.AddItem Mixture(X)
Else
    List1.AddItem Mixture(X)
EndIf
Next

Assuming all the files in your array have extensions
0
 
LVL 28

Expert Comment

by:Ark
ID: 2714912
Sorry, wrong place of bracket. Correct -

If (GetAttr(Files(X)) And vbDirectory) = vbDirectory Then

0
 
LVL 28

Accepted Solution

by:
Ark earned 100 total points
ID: 2714914
Sorry, wrong place of bracket. Correct -

If (GetAttr(Mixture(X)) And vbDirectory) = vbDirectory Then

0
 

Expert Comment

by:Olli083097
ID: 2714988
adam8:
OK, Ark knows what he is talking about. But I thought I might explain the use of GetAttr:

When you use GetAttr, it returns ALL the attributes added into one number. And to check the returned number against e.g. vbDirectory you need to use "bitwise comparison."

(Returned_value And vbDirectory) = vbDirectory if this is true, then the Returend_value contains vbDirectory

MSDN Library:
***
bitwise comparison

A bit-by-bit comparison between identically positioned bits in two numeric expressions.
***

I hope you understand this!
0
 
LVL 28

Expert Comment

by:Ark
ID: 2715161
Azra,
I hope you understand my mistake. Everybody (even you) can make it.
Cheers
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2715171
Oh I understand and I have made many similar ones myself.  Actually it wasnt your syntax error that threw me but your methods in general. I have never used the function before so I was unaware of how it was applied.  You taught me something new tonight. Thank you.    =)
0
 
LVL 28

Expert Comment

by:Ark
ID: 2715337
Azra,
"And" is very usefull when you work with a lot of flags (for samples take a look at http://www.freevbcode.com/ShowCode.Asp?ID=631)
If you reseive some Sum of flags (vbDirectory Or (or=+) vbSystem or vbHidden etc) you can easy received if your flag matches summary flags using "And":
If (GetAttr(Mixture(X)) And vbDirectory) = vbDirectory Then
' one of flags is directory (don't care system, hidden etc)
If (GetAttr(Mixture(X)) And vbSystem) = vbSystem Then
Inthis case ALL system values (folders+files) matches etc.
Cheers
0
 
LVL 1

Author Comment

by:adam8
ID: 2717788
ark,
i posted this question before i tried the code on the directory question but it was too late because i had already posted this question.

Azrasound,
if Getattr(Mixture(X)) <> Vbdirectory........
C:\WIndows\fonts is not a normal directory...
in that case it would be listed in the files section.
Get what i am saying.

I will just give the first person who answered it correct the points and that person was Ark,
but he already got some many points from me and
Olli explained it,
even though i didn't understand what he was talking about but it is fair to give the points to Ark
0
 

Expert Comment

by:Olli083097
ID: 2746672
adam8:
Haha! <smile> I was afraid you would not understand it... It's hard to explain and harder to understand! It took me quite a while to understand it... But the use of bits is quite common, and VERY useful!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Access query that references subform 5 47
SLMGR Switches Are Not Working On KMS Host 3 107
MsgBox 4 68
Make Line Items Look Good Over Mobile 2 80
Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question