Javascript FileSystemObject (FSO) provides a BuildPath method that appends the specified path by concatenating the file or folder name passed to it. BuildPath method checks the specified path whether path separation character i.e. “\” has been added or not. If path does not contain the separation character at the end then BuildPath method of FileSystemObject inserts the separation character at the end of the specified path and concatenates the file or directory name after the separation character. Javascript FSO BuildPath method enables you to build different paths based on the current path location of file system object. For example if you are working in some specified directory and want to build a new path according to the newly created directory then you can build the path using fso BuildPath method. You just need to pass the parent path and name of the new directory to the BuildPath method that will generate the complete path.

Syntax for Javascript FileSystemObject BuildPath Method

fso.BuildPath(Path, Name);

Assume fso as an object of FileSystemObject that provides the access to BuildPath method. You can see that BuildPath method accepts 2 types of parameters. Both Path and Name parameter accepts string type value, first parameter accepts string type value to specify the path and second parameter accepts string type value as Name of file or folder.

Example of Javascript FileSystemObject BuildPath Method

<script type="text/javascript">
    // initialize ActiveXObject and create an object of Scripting.FileSystemObject.
    var fso = new ActiveXObject("Scripting.FileSystemObject");

    // fso BuildPath method along with its 2 parameters as path and file/folder name
    var filePath = fso.BuildPath("C:\\Temp", "file.txt");

    // print the value returned by BuildPath method on the web page
    document.write(filePath);

    document.write("<br />");

    // path parameter passed with path separation character i.e. "\"
    filePath = fso.BuildPath("C:\\Temp\\", "file.txt");

    // above method will also print the same output: "C:\Temp\file.txt"
    document.write(filePath);

    // Output:
    // C:\Temp\file.txt
    // C:\Temp\file.txt
</script>

Continue to next tutorial: Javascript FileSystemObject CopyFile Method to learn copying a file from one place to another.

Recent JavaScript Tutorials

Javascript FSO ShortPath property

Javascript FileSystemObject (FSO) provides a ShortPath property that can be accessed using the folder object or file object returned by the GetFolder or GetFile method.

Javascript FSO Path Property

Javascript FileSystemObject (FSO) provides the Path property that can be accessed through the file object or folder object returned by the GetFile or GelFolder method

Javascript FSO Type property

Javascript FileSystemObject (FSO) provides a Type property that can be accessed through file object or folder object returned by the GetFile or GetFolder method

Javascript FSO ShortName property

Javascript FileSystemObject (FSO) provides a ShortName property that can be accessed using the folder object or file object returned by the GetFolder or GetFile method.

Javascript FSO Name Property

Javascript FileSystemObject (FSO) provides a Name property that can be accessed using file object or folder object.