Results 1 to 8 of 8

Thread: Simple dir function (newbie)

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2000
    Location
    Nashville, TN
    Posts
    54
    I have this code to return a directory listing in a folder

    dir1=dir("c:\myfolder")
    do until dir()=""
    dir1=dir
    loop

    My problem is that I want to see the last file that would show up in the name column under details.

    But if files names have spaces in them it does not like that

    Anyone have any advice
    thanks

  2. #2

    Thread Starter
    Member
    Join Date
    Feb 2000
    Location
    Nashville, TN
    Posts
    54
    It actually seems to genrate an error message when I add another file to that dir
    why?

  3. #3
    Addicted Member
    Join Date
    Aug 1999
    Location
    Ottawa,ON,Canada
    Posts
    217
    Try this:

    Code:
       Dim sFile As String
       
       sFile = Dir("c:\myfolder\", vbDirectory Or vbNormal Or vbReadOnly Or vbHidden Or vbSystem)
       
       Do While sFile <> vbNullString
          Debug.Print sFile
          sFile = Dir
       Loop
    You may notice your main problem was that you forgot the backslash after the directory you wanted to list. Also, you almost always have specify the file types as well to get a true directory listing.

    Later.

  4. #4
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Nitro
    Posts
    633
    Try this:


    Dim strExistingFile As String
    strExistingFile = Dir(gstrProcessAreaDirectory & "*.*")
    Do Until strExistingFile = ""
    List1.Additem strExistingFile
    strExistingFile = Dir()
    Loop
    Chemically Formulated As:
    Dr. Nitro

  5. #5

    Thread Starter
    Member
    Join Date
    Feb 2000
    Location
    Nashville, TN
    Posts
    54
    These do work great, however, how can I sort them

  6. #6
    Lively Member
    Join Date
    Jan 2000
    Location
    Springfield, IL
    Posts
    124
    Your problem is everytime the line do until dir()="" is executed you retrieve the next file. With the code you have you are retrieving every other file. Try using this code and see what you get.

    dir1=dir("c:\myfolder")
    do while dir1 <> ""
    dir1=dir
    loop


  7. #7
    Addicted Member
    Join Date
    Aug 1999
    Location
    Ottawa,ON,Canada
    Posts
    217
    If you're putting it into a ListBox simply set the Sorted property to True. Otherwise use something like a bubble sort on the list of files.

    If you don't know how to do a bubble sort, ask me how and I post it. It does take some coding though.

  8. #8
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Nitro
    Posts
    633
    Inside the listbox, there is a property call "Sort". Set this to "True" and there you have it.
    Chemically Formulated As:
    Dr. Nitro

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