Skip to main content

FileSystemObject.BuildPath method

Table of contents
  1. Syntax
  2. Remarks
  3. Examples

Combines a folder path and the name of a folder or file and returns the combination with valid path separators.

Syntax

object.BuildPath (path, name)

The BuildPath method syntax has these parts:

Part Description
object Required. Always the name of a FileSystemObject.
path Required. Existing path with which name is combined. Path can be absolute or relative and need not specify an existing folder.
name Required. Name of a folder or file being appended to the existing path.

Remarks

The BuildPath method inserts an additional path separator between the existing path and the name, only if necessary.

Examples

The following code illustrates the use of the BuildPath method.

Sub BuildPathDemo()
    Dim fso As Object
    Set fso = CreateObject("Scripting.FileSystemObject")
    Debug.Print fso.BuildPath("D:\ArtWork", "ReadMe.txt")
    Debug.Print fso.BuildPath("D:\ArtWork\", "ReadMe.txt")
    Debug.Print fso.BuildPath("..", "ReadMe.txt")
End Sub

Result:

D:\ArtWork\ReadMe.txt
D:\ArtWork\ReadMe.txt
..\ReadMe.txt

Leave a comment

Your email address will not be published. Required fields are marked *

Format your code: <pre><code class="language-vba">place your code here</code></pre>