Checking if a Folder Exists and if not, creating it.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Argonath
    New Member
    • Jan 2007
    • 1

    Checking if a Folder Exists and if not, creating it.

    Hi,

    I'm afraid this will no doubt horrendously basic as I'm a complete newbie to VB and have dived in without learning to do much... Start in the deep end and all.

    So if anyone could help, I'd appreciate it;

    I've got this bit of code and I couldn't for the life of me tell you why it doesn't work, if anyone else can I'd appreciate it!

    Cheers

    ----------------

    Sub Folders()

    Directory1
    Directory2

    End Sub

    Sub Directory1()

    Application.Scr eenUpdating = False

    Worksheets("Sum mary").Activate

    Dim cli As String
    Dim Job As String

    cli = Cells(6, 5).Value
    Job = Cells(1, 29).Value

    Dim FSO, Folder
    Set FSO = Server.CreateOb ject("Scripting .FileSystemObje ct")
    Folder = "\\Work\tri al reports\" & cli & " \ "
    If FSO.FolderExist s(Folder) Then

    MsgBox "Client folder exists, creating job folder for certificate"

    Else

    MkDir "\\Work\Tri al reports\" & cli & "\"

    End If

    End Sub

    Sub Directory2()

    Application.Scr eenUpdating = False

    Worksheets("Sum mary").Activate

    Dim cli As String
    Dim Job As String

    cli = Cells(6, 5).Value
    Job = Cells(1, 29).Value

    Dim FSO, File
    Set FSO = Server.CreateOb ject("Scripting .FileSystemObje ct")
    File = "\\Work\Tri al reports\" & cli & "\" & Job & "\"
    If FSO.FolderExist s(File) Then

    MsgBox "Job folder exists, please save certificate when complete"

    Else

    MkDir "\\Work\Tri al reports\" & cli & "\" & Job & "\"

    End If

    End Sub

    ----------------

    Thanks again!

    Ben
  • seshu
    New Member
    • Nov 2006
    • 156

    #2
    hi this is seshu
    i have a piece of code here but in project refrences you need to add file system object with name microsoft scripting runtime object

    on button click event
    Dim fsys As New FileSystemObjec t
    dim str as string
    str="path"
    if fsys.folderexis ts(str) then
    msgbox"folder exists"
    else
    fsys.createfold er"path of the folder to be created"\new folder name
    msgbox "folder created"
    end if
    end sub

    Comment

    • Killer42
      Recognized Expert Expert
      • Oct 2006
      • 8429

      #3
      Originally posted by Argonath
      I've got this bit of code and I couldn't for the life of me tell you why it doesn't work, if anyone else can I'd appreciate it!
      Welcome to TheScripts!

      Could you give us some idea of what result you do get? "Doesn't work" is awfully vague.

      Comment

      Working...