Name

FileSystemObject.BuildPath Method

Syntax

                  oFileSysObj.BuildPath(Path, Name)
oFileSysObj

Use: Required

Data Subtype: FileSystemObject object

Any object variable returning a FileSystemObject object.

Path

Use: Required

Data Subtype: String

A drive and/or folder path.

Name

Use: Required

Data Subtype: String

The folder or file path to append to path.

Return Value

A Variant of subtype String.

Description

Creates a single string representing a path and filename or simply a path by concatenating the path parameter with the folder or filename, adding, where required, the correct path separator for the host system.

Rules at a Glance

  • Path can be an absolute or relative path and doesn’t have to include the drive name.

  • Neither Path nor Name has to currently exist.

Programming Tips & Gotchas

  • BuildPath is really a string concatenation method rather than a filesystem method; it does not check the validity of the new folder or filename. If you intend that the method’s return value is a path, you should check it by passing it to the FolderExists method; if you intend that the method’s return value be a path and filename, you should verify it by passing it to the FileExists method.

  • The only advantage to using the BuildPath function as opposed to concatenating two strings manually is that the function selects the correct path separator.

Get VBScript in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.