+ Reply to Thread
Results 1 to 6 of 6

Check if a folder exist

  1. #1
    Registered User
    Join Date
    11-14-2005
    Posts
    37

    Check if a folder exist

    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,
    Chris

  2. #2
    Ron de Bruin
    Guest

    Re: Check if a folder exist

    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



    --
    Regards Ron de Bruin
    http://www.rondebruin.nl


    "loopoo" <[email protected]> wrote in message
    news:[email protected]...
    >
    > 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,
    > Chris
    >
    >
    > --
    > loopoo
    > ------------------------------------------------------------------------
    > loopoo's Profile: http://www.excelforum.com/member.php...o&userid=28792
    > View this thread: http://www.excelforum.com/showthread...hreadid=491380
    >




  3. #3
    Registered User
    Join Date
    11-14-2005
    Posts
    37
    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

  4. #4
    Bob Phillips
    Guest

    Re: Check if a folder exist

    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)


    "loopoo" <[email protected]> wrote in
    message news:[email protected]...
    >
    > 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,
    > Chris
    >
    >
    > --
    > loopoo
    > ------------------------------------------------------------------------
    > loopoo's Profile:

    http://www.excelforum.com/member.php...o&userid=28792
    > View this thread: http://www.excelforum.com/showthread...hreadid=491380
    >




  5. #5
    Registered User
    Join Date
    11-14-2005
    Posts
    37
    Thanks for your help, Bob!

    Chris

  6. #6
    Jim Rech
    Guest

    Re: Check if a folder exist

    Ron's solution is better because it does not change the current folder.

    --
    Jim
    "loopoo" <[email protected]> wrote in
    message news:[email protected]...
    |
    | 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...o&userid=28792
    | View this thread: http://www.excelforum.com/showthread...hreadid=491380
    |



+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1