Results 1 to 5 of 5
  1. #1
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    vbDirectory attributes

    I've never really understood the DIR function, although I use it successfully.

    Except again this morning.

    When I run this snippet, the first file **I** get is "IO.DOS".

    Why is this happening when I've (and Msoft've) used the vbDirectory attributes?

    And why do they then go on to mask the bits, unless they know already that the DIR function doesn't work as advertised?




    (snip from Word97SR2VBA help files)
    <pre>' Display the names in C: that represent directories.
    MyPath = "c:" ' Set the path.
    MyName = Dir(MyPath, vbDirectory) ' Retrieve the first entry.
    Do While MyName <> "" ' Start the loop.
    ' Ignore the current directory and the encompassing directory.
    If MyName <> "." And MyName <> ".." Then
    ' Use bitwise comparison to make sure MyName is a directory.

    If (GetAttr(MyPath & MyName) And vbDirectory) = vbDirectory Then
    Debug.Print MyName ' Display entry only if it
    End If ' it represents a directory.
    End If
    MyName = Dir ' Get next entry.
    Loop
    </pre>


    (signed) "Puzzled" of Toronto.

  2. #2
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: vbDirectory attributes

    Here's something else to watch out for:

    In the sample code MSoft tests for "." and "..". I got curious and dropped to DOS (Win95) and issued the commands:
    <pre> C:
    CD Temp
    MD ...Trash
    dir /od
    </pre>



    "Illuminating" is not the word that springs to mind ...

    (clever use of the three periods there, eh!)



    Although a call (in Immediate window) to
    <pre>?getattr("c:TEMP...eras")
    </pre>

    generates a runtime error '52' "Bad file name or number"


    Now I'm faced with the prospect of Word97 objecting to a directory name that its host platform Win95 allows.


    And yes, Scandisk condones it; it even includes my directory in its message "Checking Folders ...".

  3. #3
    Super Moderator
    Join Date
    Dec 2000
    Location
    Renton, Washington, USA
    Posts
    12,560
    Thanks
    0
    Thanked 4 Times in 4 Posts

    Re: vbDirectory attributes

    In the DOS world, folders could NOT contain dots (.'s), they would become hidden extensions. You could see what was before the dot's but not after, unless you type them in the path. This was a old trick in hiding folders from even the IT people, until Norton's came out with their tools.

    The DOS command CD ., would back up one level, cd .. 2 levels and CD ... 3 levels or home. I may be wrong on these, but that is how it worked.

    Now running HP Pavilion a6528p, with Win7 64 Bit OS.

  4. #4
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: vbDirectory attributes

    That is how it worked and still does in MSDOS (Windows ME)

    One dot represents the current directory so CD . (one dot) does not do much. CD .. (2 dots) takes you back one step etc. CD . (backslash dot) takes you to the root directory of the curtrent drive.

    Andrew C

  5. #5
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: vbDirectory attributes

    >Now I'm faced with the prospect of Word97 objecting to a directory name that its host platform Win95 allows.


    Thank you Dave and Andrew.

    Now, about the little matter above. Any comments?


    I know you're not responsible for Win95/Word97. Me neither. For now I've had to become one of those despised people who depends on On Error.

    I could write a little function that filters out all forms of invalid names, I suppose. That being the case, does anyone here have a link to a list of allowable syntax for valid file names under Win95?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •