DIR()

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have some VBA code in a form that scans the users hard drive to get
directory information and loads it into a listbox. It works great except for
directories with special characters in the name such as lastname, firstname.
The comma is being interpreted as a separator in the code below

ChDrive (myDrive)
Chdir (myPath)
ctr = 0
myName = Dir("*.*", vbDirectory)
Do While myName <> ""
If myName <> "." And myName <> ".." Then
If (GetAttr(myPath & "\" & myName) And vbDirectory) =
vbDirectory Then
Me.filename_entries.AddItem myName, ctr
ctr = ctr + 1
End If
End If
myName = Dir
Loop

for the directory lastname, firstname I'm getting two entries; lastname and
firstname...any idea why?

Thanks in advance for your help!
 
It is as you suspect - the comma is being trated as a separator. Try this:

Me.filename_entries.AddItem Chr$(34) & myName & Chr$(34), ctr
 
Back
Top