Solved

Get Attributes

Posted on 2000-04-13
14
222 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
 
LVL 27

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 27

Expert Comment

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

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

0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 27

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 27

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 27

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

758 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now