From: Karl E. Peterson on
I guess I was bored this afternoon? So, here's a puzzle for the long weekend! :-)

I was trying to codify the rules VB uses for including results in a Dir loop, based
on what attributes are passed to it. This is the best I've come up with so far:

Private Function VBDirInclude(ByVal AttrFound As Long, ByVal AttrSought As Long)
As Boolean
Dim atFound As Long, atSought As Long
Dim hsFound As Long, hsSought As Long
Dim Result As Boolean

Const FILE_ATTRIBUTE_NORMAL As Long = &H80
Const atIgnore As Long = vbArchive Or vbReadOnly Or FILE_ATTRIBUTE_NORMAL
Const vbHiddenSystem = vbHidden Or vbSystem

' VB always includes files with normal, readonly, and
' archived attributes set, so turn those off.
atFound = AttrFound And Not atIgnore
atSought = AttrSought And Not atIgnore

' Automatic pass if the ignored attributes are the
' only ones set, or attributes match exactly.
If (atFound = 0) Or (atFound = atSought) Then
VBDirInclude = True
Exit Function
End If

' Directories only included when specifically requested.
If (atFound And vbDirectory) Then
If (atSought And vbDirectory) = False Then
Exit Function
End If
End If

' If both hidden and system are set, files will not match
' unless both attributes were requested.
hsFound = atFound And vbHiddenSystem
hsSought = atSought And vbHiddenSystem
If hsFound Then
If hsSought Then
If (hsFound = vbHiddenSystem) Then
VBDirInclude = CBool(hsSought = vbHiddenSystem)
Else
VBDirInclude = CBool(hsFound And hsSought)
End If
End If
End If
End Function

Anyone see any "issues" with that? A better way to code it? Do note that the code
above is not strictly in accordance with the documentation. For instance, the docs
say:

vbReadOnly: Specifies read-only files in addition to files with no attributes.

Nope. Read-only files/folders are included in every Dir loop, regardless of whether
or not you ask for them. Surprise, surprise, huh? <g>

Also, completely off-base question, wth's vbAlias in the VbFileAttribute enum?

Have fun...
--
..NET: It's About Trust!
http://vfred.mvps.org


From: Kevin Provance on
Dude, I avoid Dir like the plague (opting of course for it's API
equivilants). It's just so unreliable on so many levels.

I can however address the vbAlias question. It's a Macintosh thing, more or
less. Filenames under that OS can be, well..aliased. I suspect the reason
we see it in VB is backwards compatibility for the Mac version of Office.
That would be my guess. Under Windows it has no use whatsoever.

- Kev

"Karl E. Peterson" <karl(a)mvps.org> wrote in message
news:OY2NiUX3IHA.3544(a)TK2MSFTNGP06.phx.gbl...
|I guess I was bored this afternoon? So, here's a puzzle for the long
weekend! :-)
|
| I was trying to codify the rules VB uses for including results in a Dir
loop, based
| on what attributes are passed to it. This is the best I've come up with
so far:
|
| Private Function VBDirInclude(ByVal AttrFound As Long, ByVal AttrSought
As Long)
| As Boolean
| Dim atFound As Long, atSought As Long
| Dim hsFound As Long, hsSought As Long
| Dim Result As Boolean
|
| Const FILE_ATTRIBUTE_NORMAL As Long = &H80
| Const atIgnore As Long = vbArchive Or vbReadOnly Or
FILE_ATTRIBUTE_NORMAL
| Const vbHiddenSystem = vbHidden Or vbSystem
|
| ' VB always includes files with normal, readonly, and
| ' archived attributes set, so turn those off.
| atFound = AttrFound And Not atIgnore
| atSought = AttrSought And Not atIgnore
|
| ' Automatic pass if the ignored attributes are the
| ' only ones set, or attributes match exactly.
| If (atFound = 0) Or (atFound = atSought) Then
| VBDirInclude = True
| Exit Function
| End If
|
| ' Directories only included when specifically requested.
| If (atFound And vbDirectory) Then
| If (atSought And vbDirectory) = False Then
| Exit Function
| End If
| End If
|
| ' If both hidden and system are set, files will not match
| ' unless both attributes were requested.
| hsFound = atFound And vbHiddenSystem
| hsSought = atSought And vbHiddenSystem
| If hsFound Then
| If hsSought Then
| If (hsFound = vbHiddenSystem) Then
| VBDirInclude = CBool(hsSought = vbHiddenSystem)
| Else
| VBDirInclude = CBool(hsFound And hsSought)
| End If
| End If
| End If
| End Function
|
| Anyone see any "issues" with that? A better way to code it? Do note that
the code
| above is not strictly in accordance with the documentation. For instance,
the docs
| say:
|
| vbReadOnly: Specifies read-only files in addition to files with no
attributes.
|
| Nope. Read-only files/folders are included in every Dir loop, regardless
of whether
| or not you ask for them. Surprise, surprise, huh? <g>
|
| Also, completely off-base question, wth's vbAlias in the VbFileAttribute
enum?
|
| Have fun...
| --
| .NET: It's About Trust!
| http://vfred.mvps.org
|
|


From: Larry Serflaten on

"Karl E. Peterson" <karl(a)mvps.org> wrote

> I was trying to codify the rules VB uses for including results in a Dir loop, based
> on what attributes are passed to it. This is the best I've come up with so far:

> Anyone see any "issues" with that? A better way to code it? Do note that the code
> above is not strictly in accordance with the documentation. For instance, the docs
> say:

What if the sought attribute is for a Volume lable (8)? How are you obtaining the
found attribute? I would think you could simplfy that all to some boolean expression....

> Also, completely off-base question, wth's vbAlias in the VbFileAttribute enum?

Links and shortcuts?

LFS


From: Tony Proctor on
Macintosh thing? NTFS supports filename aliases, as does UNIX (see soft/hard
links), VMS, and I'm sure other O/S's too. In other words, the concept has
been around a long time

Tony Proctor

"Kevin Provance" <casey(a)tpasoft.com> wrote in message
news:eAQ340X3IHA.3508(a)TK2MSFTNGP02.phx.gbl...
> Dude, I avoid Dir like the plague (opting of course for it's API
> equivilants). It's just so unreliable on so many levels.
>
> I can however address the vbAlias question. It's a Macintosh thing, more
> or
> less. Filenames under that OS can be, well..aliased. I suspect the
> reason
> we see it in VB is backwards compatibility for the Mac version of Office.
> That would be my guess. Under Windows it has no use whatsoever.
>
> - Kev
>
> "Karl E. Peterson" <karl(a)mvps.org> wrote in message
> news:OY2NiUX3IHA.3544(a)TK2MSFTNGP06.phx.gbl...
> |I guess I was bored this afternoon? So, here's a puzzle for the long
> weekend! :-)
> |
> | I was trying to codify the rules VB uses for including results in a Dir
> loop, based
> | on what attributes are passed to it. This is the best I've come up with
> so far:
> |
> | Private Function VBDirInclude(ByVal AttrFound As Long, ByVal
> AttrSought
> As Long)
> | As Boolean
> | Dim atFound As Long, atSought As Long
> | Dim hsFound As Long, hsSought As Long
> | Dim Result As Boolean
> |
> | Const FILE_ATTRIBUTE_NORMAL As Long = &H80
> | Const atIgnore As Long = vbArchive Or vbReadOnly Or
> FILE_ATTRIBUTE_NORMAL
> | Const vbHiddenSystem = vbHidden Or vbSystem
> |
> | ' VB always includes files with normal, readonly, and
> | ' archived attributes set, so turn those off.
> | atFound = AttrFound And Not atIgnore
> | atSought = AttrSought And Not atIgnore
> |
> | ' Automatic pass if the ignored attributes are the
> | ' only ones set, or attributes match exactly.
> | If (atFound = 0) Or (atFound = atSought) Then
> | VBDirInclude = True
> | Exit Function
> | End If
> |
> | ' Directories only included when specifically requested.
> | If (atFound And vbDirectory) Then
> | If (atSought And vbDirectory) = False Then
> | Exit Function
> | End If
> | End If
> |
> | ' If both hidden and system are set, files will not match
> | ' unless both attributes were requested.
> | hsFound = atFound And vbHiddenSystem
> | hsSought = atSought And vbHiddenSystem
> | If hsFound Then
> | If hsSought Then
> | If (hsFound = vbHiddenSystem) Then
> | VBDirInclude = CBool(hsSought = vbHiddenSystem)
> | Else
> | VBDirInclude = CBool(hsFound And hsSought)
> | End If
> | End If
> | End If
> | End Function
> |
> | Anyone see any "issues" with that? A better way to code it? Do note
> that
> the code
> | above is not strictly in accordance with the documentation. For
> instance,
> the docs
> | say:
> |
> | vbReadOnly: Specifies read-only files in addition to files with no
> attributes.
> |
> | Nope. Read-only files/folders are included in every Dir loop,
> regardless
> of whether
> | or not you ask for them. Surprise, surprise, huh? <g>
> |
> | Also, completely off-base question, wth's vbAlias in the VbFileAttribute
> enum?
> |
> | Have fun...
> | --
> | .NET: It's About Trust!
> | http://vfred.mvps.org
> |
> |
>
>


From: Kevin Provance on
Well, yeah? Duh! I was addressing Karl's question, which as I understood
it was the purpose of having such a flag in VB/VBA. Since VBA is available
under Office for Mac, it's there for the benefit of Mac users who use VBA.
Hence, a Macintosh thing. If there was a 'Nix version of VBA then I would
have uncluded this as well.

As far as having any functionality under Windows, there is none in as far as
the flag being present and available.


"Tony Proctor" <tony_proctor(a)aimtechnology_NoMoreSPAM_.com> wrote in message
news:%23MlZmBd3IHA.5060(a)TK2MSFTNGP02.phx.gbl...
| Macintosh thing? NTFS supports filename aliases, as does UNIX (see
soft/hard
| links), VMS, and I'm sure other O/S's too. In other words, the concept has
| been around a long time
|
| Tony Proctor
|
| "Kevin Provance" <casey(a)tpasoft.com> wrote in message
| news:eAQ340X3IHA.3508(a)TK2MSFTNGP02.phx.gbl...
| > Dude, I avoid Dir like the plague (opting of course for it's API
| > equivilants). It's just so unreliable on so many levels.
| >
| > I can however address the vbAlias question. It's a Macintosh thing,
more
| > or
| > less. Filenames under that OS can be, well..aliased. I suspect the
| > reason
| > we see it in VB is backwards compatibility for the Mac version of
Office.
| > That would be my guess. Under Windows it has no use whatsoever.
| >
| > - Kev
| >
| > "Karl E. Peterson" <karl(a)mvps.org> wrote in message
| > news:OY2NiUX3IHA.3544(a)TK2MSFTNGP06.phx.gbl...
| > |I guess I was bored this afternoon? So, here's a puzzle for the long
| > weekend! :-)
| > |
| > | I was trying to codify the rules VB uses for including results in a
Dir
| > loop, based
| > | on what attributes are passed to it. This is the best I've come up
with
| > so far:
| > |
| > | Private Function VBDirInclude(ByVal AttrFound As Long, ByVal
| > AttrSought
| > As Long)
| > | As Boolean
| > | Dim atFound As Long, atSought As Long
| > | Dim hsFound As Long, hsSought As Long
| > | Dim Result As Boolean
| > |
| > | Const FILE_ATTRIBUTE_NORMAL As Long = &H80
| > | Const atIgnore As Long = vbArchive Or vbReadOnly Or
| > FILE_ATTRIBUTE_NORMAL
| > | Const vbHiddenSystem = vbHidden Or vbSystem
| > |
| > | ' VB always includes files with normal, readonly, and
| > | ' archived attributes set, so turn those off.
| > | atFound = AttrFound And Not atIgnore
| > | atSought = AttrSought And Not atIgnore
| > |
| > | ' Automatic pass if the ignored attributes are the
| > | ' only ones set, or attributes match exactly.
| > | If (atFound = 0) Or (atFound = atSought) Then
| > | VBDirInclude = True
| > | Exit Function
| > | End If
| > |
| > | ' Directories only included when specifically requested.
| > | If (atFound And vbDirectory) Then
| > | If (atSought And vbDirectory) = False Then
| > | Exit Function
| > | End If
| > | End If
| > |
| > | ' If both hidden and system are set, files will not match
| > | ' unless both attributes were requested.
| > | hsFound = atFound And vbHiddenSystem
| > | hsSought = atSought And vbHiddenSystem
| > | If hsFound Then
| > | If hsSought Then
| > | If (hsFound = vbHiddenSystem) Then
| > | VBDirInclude = CBool(hsSought = vbHiddenSystem)
| > | Else
| > | VBDirInclude = CBool(hsFound And hsSought)
| > | End If
| > | End If
| > | End If
| > | End Function
| > |
| > | Anyone see any "issues" with that? A better way to code it? Do note
| > that
| > the code
| > | above is not strictly in accordance with the documentation. For
| > instance,
| > the docs
| > | say:
| > |
| > | vbReadOnly: Specifies read-only files in addition to files with no
| > attributes.
| > |
| > | Nope. Read-only files/folders are included in every Dir loop,
| > regardless
| > of whether
| > | or not you ask for them. Surprise, surprise, huh? <g>
| > |
| > | Also, completely off-base question, wth's vbAlias in the
VbFileAttribute
| > enum?
| > |
| > | Have fun...
| > | --
| > | .NET: It's About Trust!
| > | http://vfred.mvps.org
| > |
| > |
| >
| >
|
|