-
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
-
It actually seems to genrate an error message when I add another file to that dir
why?
-
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.
-
Try this:
Dim strExistingFile As String
strExistingFile = Dir(gstrProcessAreaDirectory & "*.*")
Do Until strExistingFile = ""
List1.Additem strExistingFile
strExistingFile = Dir()
Loop
-
These do work great, however, how can I sort them
-
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
-
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.
-
Inside the listbox, there is a property call "Sort". Set this to "True" and there you have it.