O'Reilly logo

VBScript in a Nutshell, 2nd Edition by Ron Petrusha, Matt Childs, Paul Lomax

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

FileSystemObject.CreateFolder Method

Syntax

                  oFileSysObj
                  .CreateFolder(Path)
oFileSysObj

Use: Required

Data Type: FileSystemObject object

A FileSystemObject object.

Path

Use: Required

Data Type: 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.

  • Path can 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 Path already exists, the method generates runtime error, “File already exists.”

Programming Tips and Gotchas

  • If Path is read-only, the CreateFolder method fails.

  • If Path already exists, the method generates runtime error 58, “File already exists.”

  • If the user has adequate rights, Path can be a network path or share name. For example:

    CreateFolder "\\NTSERV1\d$\RootTwo\newFolder"
    CreateFolder "\\NTSERV1\RootTest\newFolder"
  • You must use the Set statement 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")

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required