Results 1 to 14 of 14

Thread: Dir$

  1. #1
    Guest

    Post

    I'm using a loop containing:

    Dir$("*.*", vbDirectory)

    to get a list of directories in the current folder, but it's also returning all the files in the current folder (which I don't want!!)

    Any ideas why? (And more to the point...how to stop it!!)

    ------------------
    Matthew Ralston
    E-Mail: [email protected]
    ICQ: 31422892
    Web Site: My Home Page
    AKA: ...::: The Fragmeinster :::... (On Quake 3 World Forums)

    Sorry about my English, but my Scouse is dead good!

  2. #2
    Frenzied Member Buzby's Avatar
    Join Date
    Jan 1999
    Location
    UK
    Posts
    1,670

    Post

    Try

    Dir$("*.", vbDirectory)

    to get the directories only - this works in DOS (I've never tried it in VB!)

    Note: In DOS at least, this returns any files/folders with no extension (normally this is just the folders but you can sometimes get a few files turning up as well)



    ------------------
    Mark "Buzby" Beeton
    VB Developer
    [email protected]



  3. #3
    Frenzied Member Buzby's Avatar
    Join Date
    Jan 1999
    Location
    UK
    Posts
    1,670

    Post

    Try

    Dir$("*.", vbDirectory)

    to get the directories only - this works in DOS (I've never tried it in VB!)

    Note: In DOS at least, this returns any files/folders with no extension (normally this is just the folders but you can sometimes get a few files turning up as well)



    ------------------
    Mark "Buzby" Beeton
    VB Developer
    [email protected]



  4. #4
    Frenzied Member Buzby's Avatar
    Join Date
    Jan 1999
    Location
    UK
    Posts
    1,670

    Post

    Try

    Dir$("*.", vbDirectory)

    to get the directories only - this works in DOS (I've never tried it in VB!)

    Note: In DOS at least, this returns any files/folders with no extension (normally this is just the folders but you can sometimes get a few files turning up as well)



    ------------------
    Mark "Buzby" Beeton
    VB Developer
    [email protected]



  5. #5
    Guest

    Post

    Sorry, Azzmodan, your method still returns all the files in the specified path - as well as the folders. I ONLY want the folders!!

    Alternatively...is there a RELIABLE way to determine if a path points to a file or folder...I could filter them out that way...

    ------------------
    Matthew Ralston
    E-Mail: [email protected]
    ICQ: 31422892
    Web Site: My Home Page
    AKA: ...::: The Fragmeinster :::... (On Quake 3 World Forums)

    Sorry about my English, but my Scouse is dead good!

  6. #6
    Guest

    Post

    I've just had a look at the help file and it says that "vbDirectory":
    Specifies directories or folders in addition to files with no attributes.
    How can I stop Dir$ from returning "files with no attributes".

    ------------------
    Matthew Ralston
    E-Mail: [email protected]
    ICQ: 31422892
    Web Site: My Home Page
    AKA: ...::: The Fragmeinster :::... (On Quake 3 World Forums)

    Sorry about my English, but my Scouse is dead good!

  7. #7
    Hyperactive Member Al Smith's Avatar
    Join Date
    May 1999
    Location
    Marcellus, MI. USA
    Posts
    330

    Post

    Hi,
    Might you be able to use something like this?

    A DirListBox control displays directories and paths at run time. Use this control to display a hierarchical list of directories. You can create dialog boxes that, for example, enable a user to open a file from a list of files in all available directories.

    Syntax

    DirListBox

    Remarks

    Set the List, ListCount, and ListIndex properties to enable a user to access items in a list. If you also display the DriveListBox and FileListBox controls, you can write code to synchronize them with the DirListBox control and with each other.

    Al.


    ------------------
    A computer is a tool, not a toy.
    <A HREF="mailto:[email protected]
    [email protected]">[email protected]
    [email protected]</A>

  8. #8
    Fanatic Member r0ach's Avatar
    Join Date
    Dec 1999
    Location
    South Africa
    Posts
    722

    Post

    Try
    Code:
    Dir$("*.*", (vbDirectory) And (Not vbNormal))
    I dunno if it will work, but it's worth a try

    ------------------
    r0ach(tm)

  9. #9
    Guest

    Post

    Nope, sorry...nice try though!! I considered using something like that already and neither mine nor yours worked.

    As for using a directory list box, I'd rather avoid this because the program is running as a CGI program on a web server...so it needs to be as small, fast and memory efficient as possible!

    Any other ideas? Is there an API that returns only folders?

    ------------------
    Matthew Ralston
    E-Mail: [email protected]
    ICQ: 31422892
    Web Site: My Home Page
    AKA: ...::: The Fragmeinster :::... (On Quake 3 World Forums)

    Sorry about my English, but my Scouse is dead good!

  10. #10
    Guest

    Post

    Can

    Public Declare Function GetFileType Lib "kernel32" Alias "GetFileType" (ByVal hFile As Long) As Long

    tell me if a file is really a folder? Dunno how to use this...?

    ------------------
    Matthew Ralston
    E-Mail: [email protected]
    ICQ: 31422892
    Web Site: My Home Page
    AKA: ...::: The Fragmeinster :::... (On Quake 3 World Forums)

    Sorry about my English, but my Scouse is dead good!

  11. #11
    Guest

    Post

    Euh use, Dir("C:\",vbdirectory) for all Dir's in the specified dir.

    If you use "*." you don't get any dir's with extensions(and some dir's have extensions)

    ------------------

    Vincent van den Braken
    EMail: [email protected]
    ICQ: 15440110
    Homepage: http://www.azzmodan.demon.nl




  12. #12
    Guest

    Post

    Come on! Help me out here!

    ------------------
    Matthew Ralston
    E-Mail: [email protected]
    ICQ: 31422892
    Web Site: My Home Page
    AKA: ...::: The Fragmeinster :::... (On Quake 3 World Forums)

    Sorry about my English, but my Scouse is dead good!

  13. #13
    Hyperactive Member
    Join Date
    Jan 1999
    Location
    Rotterdam, Netherlands
    Posts
    386

    Post

    Sorry, but this is just plain simple VB programming.. should be able to find it out yourself.. but anyway, this gave a nice listing of all my folders in the C:\Program Files\ folder:
    Code:
        Dim s As String
        Dim sStartIn As String
        sStartIn = "C:\Program Files\"
        s = Dir$(sStartIn, vbDirectory)
        Do While s &lt;&gt; ""
            If s &lt;&gt; "." And s &lt;&gt; ".." Then
                If (GetAttr(sStartIn & s) And vbDirectory) Then
                    Debug.Print s
                End If
            End If
            s = Dir$()
        Loop

  14. #14
    Guest

    Post

    Thanks!! An asnwer that works!

    I didn't even know the getattr function existed...silly me!

    My directory listing looks much better now!

    ------------------
    Matthew Ralston
    E-Mail: [email protected]
    ICQ: 31422892
    Web Site: My Home Page
    AKA: ...::: The Fragmeinster :::... (On Quake 3 World Forums)

    Sorry about my English, but my Scouse is dead good!

Posting Permissions

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



Click Here to Expand Forum to Full Width