Check Directory (Urgent)

T

Tim

Hi everyone,

I used MKDir to create directory. If the directory does
not exist, then it will work fine. But, if the directory
exists, then it will give me an error message.

Could anyone tell me how to check the directory exist or
not?

Similar like this:

If (c:\temp does not exist) then
MKDir "c:\temp"
Else
(do nothing)
End if

Thanks.

Tim.
 
D

Dirk Goldgar

Tim said:
Hi everyone,

I used MKDir to create directory. If the directory does
not exist, then it will work fine. But, if the directory
exists, then it will give me an error message.

Could anyone tell me how to check the directory exist or
not?

Similar like this:

If (c:\temp does not exist) then
MKDir "c:\temp"
Else
(do nothing)
End if

Thanks.

Try this:

If Len(Dir("C:\Temp", vbDirectory)) = 0 Then
' The directory doesn't exist, so create it.
MkDir "C:\temp"
End If
 
Top