Name
FileSystemObject.CreateFolder Method
Syntax
oFileSysObj.CreateFolder(Path)
-
oFileSysObj Use: Required
Data Subtype: FileSystemObject object
Any object variable returning a FileSystemObject object.
-
Path Use: Required
Data Subtype: String
An expression that returns the name of the new folder to create.
Return Value
A Folder object.
Description
Creates a single new folder in the path specified and returns its Folder object.
Rules at a Glance
Wildcard characters aren’t allowed in
Path.Pathcan be a relative or absolute path.If no path is specified in
Path, the current drive and directory are used.If the last folder in
Pathalready exists, the method generates run-time error, “File already exists.”
Programming Tips & Gotchas
If
Pathis read-only, the CreateFolder method fails.If
Pathalready exists, the method generates runtime error 58, “File already exists.”If the user has adequate rights,
Pathcan be a network path or share name. For example:CreateFolder "\\NTSERV1\d$\RootTwo\newFolder" CreateFolder "\\NTSERV1\RootTest\newFolder"
You must use the
Setstatement to assign the Folder object to an object variable. For example:Dim oFileSys Dim oFolder Set oFileSys = CreateObject("Scripting.FileSystemObject") Set oFolder = oFileSys.CreateFolder("MyFolder")
See Also
| Folders.Add Method |
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access