Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Get Attributes

Posted on 2000-04-13
14
Medium Priority
?
230 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 400 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying 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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

609 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