DIR()

P

PeterM

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!
 
R

Ron Hinds

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top