DIR for valid directory return blank

  • Thread starter Thread starter darren via AccessMonster.com
  • Start date Start date
D

darren via AccessMonster.com

Hi

Stumped a bit on this.

I have code to check whether a folder exists. However, when testing this on a
valid folder Dir returns an empty string.

If I debug.print the string used for the path and try and call it in the
inmmediate window it also returns blank. However, if I then overtype it
character for character and call it again then it returns the correct value???
?

The debug.print value and the typed value are visually identical?

Any ideas?

Thanks
 
hi Darren,
I have code to check whether a folder exists. However, when testing this on a
valid folder Dir returns an empty string.
Any ideas?
Yeah, post your code. Don't like to guess today.


mfG
--> stefan <--
 
Dim strFolder As String
Dim strSubfolder As String
Dim strBEFolder As String
Dim strList As String
Dim i As Integer
Dim fls() As String

i = 0

Me.cboTeam.RowSource = ""

strFolder = Environ("USERPROFILE") & "\FinApps\"

strSubfolder = Dir$(strFolder, vbDirectory)
Do While Len(strSubfolder) > 0
If strSubfolder <> "." And strSubfolder <> ".." Then
i = i + 1
ReDim Preserve fls(i) As String
fls(i) = strSubfolder
End If
strSubfolder = Dir$()
Loop

On Error Resume Next
For i = 1 To UBound(fls())
strSubfolder = fls(i)

strBEFolder = strFolder & strSubfolder & "\support"

If Len(Dir(strBEFolder, vbDirectory)) <> 0 Then
strList = strList & "; '" & strSubfolder & "'"
End If

Next i

Me.cboTeam.RowSource = strList
 
Example resulting string for strBEFolder:

C:\Documents and Settings\jsmith\FinApps\TEST\support

Have considered the spaces in path but it didn't make a difference.

When I type Dir("C:\Documents and Settings\jsmith\FinApps\TEST\support",
vbDirectory) in the immediate window it works. But in VBA Dir(Dir(strBEFolder,
vbDirectory) returns blank.
 
hi darren,
Example resulting string for strBEFolder:
C:\Documents and Settings\jsmith\FinApps\TEST\support
Try using some Debug.?:

Dim strFolder As String
Dim strSubfolder As String
Dim strBEFolder As String
Dim strList As String
Dim i As Integer
Dim fls() As String

i = 0
strFolder = Environ("USERPROFILE") & "\FinApps\"
strSubfolder = Dir$(strFolder, vbDirectory)

Do While Len(strSubfolder) > 0
Debug.Print "new subfolder: " & strSubfolder
If strSubfolder <> "." And strSubfolder <> ".." Then
ReDim Preserve fls(i) As String
fls(i) = strSubfolder
i = i + 1
End If
strSubfolder = Dir$()
Loop
Debug.Print "folder count:" & UBound(fls())

On Error Resume Next

For i = LBound(fls()) To UBound(fls())
Debug.Print i; fls(i)
strSubfolder = fls(i)
strBEFolder = strFolder & strSubfolder & "\support"
Debug.Print "strBEFolder:""" & strBEFolder & """"
If Len(Dir(strBEFolder, vbDirectory)) <> 0 Then
strList = strList & "; '" & strSubfolder & "'"
End If
Next i

Debug.Print "strList=" & strList

This gives me:
new subfolder: .
new subfolder: ..
new subfolder: support
folder count:0
0 support
strBEFolder:"C:\Dokumente und Einstellungen\ste5an\FinApps\support\support"
strList=

As you can see, you do not assamble your strBEFolder correctly.


mfG
--> stefan <--
 
hi,

Stefan said:
For i = LBound(fls()) To UBound(fls())
Forgot to mention this little glitch. You had a 1 instead of LBound().
Arrays start normaly at index 0.


mfG
--> stefan <--
 
Thanks Stefan, I've not used arrays too much to date.

Did have debug.print in but went through them again. Founds a very subtle
spelling in my original code. Doh! All sorted now.

Danke.
 

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

Back
Top