• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

How to create New Folder in Path.

riya

Member
Hi All,
I have a problem where I want to create a New Folder in a given path, could you please assist.
 
Code:
Sub test()
Set c = CreateObject("Scripting.FileSystemObject")
f = "C:\NewF" 'Change folder name and path here
If c.FolderExists(f) Then
MsgBox "Folder With Same Name is Already Exists There"
Else
c.CreateFolder f
MsgBox "Folder Created"
End If

End Sub
[code/]
 
Another option
Code:
Sub riya()
   Dim Pth As String, NewFolder As String
  
   Pth = "C:\Testa\"
   NewFolder = "Testb"
   If Dir(Pth, vbDirectory) <> "" And Dir(Pth & NewFolder, vbDirectory) = "" Then
      MkDir (Pth & NewFolder)
   End If
End Sub
 
Code:
Sub test()
Set c = CreateObject("Scripting.FileSystemObject")
f = "C:\NewF" 'Change folder name and path here
If c.FolderExists(f) Then
MsgBox "Folder With Same Name is Already Exists There"
Else
c.CreateFolder f
MsgBox "Folder Created"
End If

End Sub
[code/]
Hi Ankush.. Thanks for your reply, could you please check again every time I am getting msgbox "Folder With Same Name is Already Exists There" and not creating folder. [U]Fluff13[/U] code is working as per my requirement.
 
Another option
Code:
Sub riya()
   Dim Pth As String, NewFolder As String
 
   Pth = "C:\Testa\"
   NewFolder = "Testb"
   If Dir(Pth, vbDirectory) <> "" And Dir(Pth & NewFolder, vbDirectory) = "" Then
      MkDir (Pth & NewFolder)
   End If
End Sub
Thanks Fluff.. That I want exactly :) Do we have any other method to create Folder or have to use VbDir.
 
Hi Ankush.. Thanks for your reply, could you please check again every time I am getting msgbox "Folder With Same Name is Already Exists There" and not creating folder. [U]Fluff13[/U] code is working as per my requirement.
This is because folder with same name have been already there...get rid of that folder or change folder name and run.
 
Back
Top