Check if a folder exist

  • Thread starter Thread starter loopoo
  • Start date Start date
L

loopoo

Hi!

Can anyone please help me on the following issue:
I need to know how can I check if a folder exist (I have the full path
let's say D:\Temp).

Thanks in advance,
Chri
 
Hi

Try this

Sub TestDirectory()
Dim Dirname As String
Dim fs As Object
Set fs = CreateObject("Scripting.FileSystemObject")
Dirname = "C:\MyDir"
If Not fs.FolderExists(Dirname) Then
MsgBox "not Exist"
Else
MsgBox "Exist"
End If
End Sub
 
Thanks for your help, Ron.

Someone else helped me first with thie solution on another forum:

Function FolderExists(strPath) As Boolean

On Error Resume Next

ChDir strPath
If Err.Number <> 76 Then
FolderExists = True
Else
FolderExists = False
End If

End Function

I think yours is good too.

Once again,
Thanks for your help.

Chris
 
Here is a function that you can use

'-----------------------------------------------------------------
Function FolderExists(Folder) As Boolean
'-----------------------------------------------------------------
Dim sFolder As String
On Error Resume Next
sFolder = Dir(Folder, vbDirectory)
If sFolder <> "" Then
If (GetAttr(sFolder) And vbDirectory) = vbDirectory Then
FolderExists = True
End If
End If
End Function


--

HTH

RP
(remove nothere from the email address if mailing direct)
 
Ron's solution is better because it does not change the current folder.

--
Jim
message |
| Thanks for your help, Ron.
|
| Someone else helped me first with thie solution on another forum:
|
| Function FolderExists(strPath) As Boolean
|
| On Error Resume Next
|
| ChDir strPath
| If Err.Number <> 76 Then
| FolderExists = True
| Else
| FolderExists = False
| End If
|
| End Function
|
| I think yours is good too.
|
| Once again,
| Thanks for your help.
|
| Chris
|
|
| --
| loopoo
| ------------------------------------------------------------------------
| loopoo's Profile:
http://www.excelforum.com/member.php?action=getinfo&userid=28792
| View this thread: http://www.excelforum.com/showthread.php?threadid=491380
|
 

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

Similar Threads


Back
Top