how check if folder exist

Discussion in 'C#' started by wacamoi, May 6, 2009.

  1. #1
    I know how to check if a file is existed or not.
    fs.FileExists(Path&"file.asp")

    but how to check if a folder is existed or not.

    Please help


    Thanks
     
    wacamoi, May 6, 2009 IP
  2. mavili

    mavili Active Member

    Messages:
    11
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    88
    #2
    you can use like:

    if fs.FolderExists("c:\asp")=true then ...

    (you have the appropriate permissions to view files and folder)
     
    mavili, May 6, 2009 IP
    wacamoi likes this.
  3. wacamoi

    wacamoi Peon

    Messages:
    810
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks,

    why it does not work for fs.FolderExists("c:\asp\") ?

    Regards
     
    wacamoi, May 6, 2009 IP
  4. VishalVasani

    VishalVasani Peon

    Messages:
    560
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Hello,

    You can used below code
    
    Function ReportFolderStatus(fldr)
      Dim fso, msg
      Set fso = CreateObject("Scripting.FileSystemObject")
      If (fso.FolderExists(fldr)) Then
        msg = fldr & " exists."
      Else
        msg = fldr & " doesn't exist."
      End If
      ReportFolderStatus = msg
    End Function
    
    Code (markup):
    Function return folder status
     
    VishalVasani, May 6, 2009 IP
    wacamoi likes this.