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
 

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