Javascript FileSystemObject (FSO) provides the ParentFolder property that can be accessed through the file object or folder object returned by the GetFile or GetFolder method. ParentFolder property returns the folder object associated with the specified file or folder in which it is located. Folder object returned by the ParentFolder property can further access the method and properties associated with folder object e.g: DateCreated, DataLastModified, Move etc.

Syntax for Javascript FSO ParentFolder property

fileObj.ParentFolder

// or 
folderObj.ParentFolder

Both above syntaxes show the way of using the file object and folder object to access the ParentFolder property. GetFile method returns the file object and GetFolder method returns the folder object that can be used to access the ParentFolder property associated with the specified file or folder. In simple words you can say that ParentFolder property returns the path of the folder in which the specified file or folder resides. This property also works as folder object.

Example 1

File object to get the value of ParentFolder property

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

    // object created for file object returned by GetFile method
    var fileObj = fso.GetFile("C:\\Temp\\textFile.txt");

    document.write("<b>File Name: </b>" + fileObj.Name);

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

    // Output: 
    // ParentFolder : C:\Temp
</script>

Example 2

Folder object to get the value of ParentFolder property

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

    // object created for folder object returned by GetFolder method
    var folderObj = fso.GetFolder("C:\\Temp\\myFolder");

    document.write("<b>Folder Name: </b>" + folderObj.Name);

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

    // Output: 
    // ParentFolder : C:\Temp
</script>

Continue to next tutorial: Javascript FSO Path Property to learn how to get the full path of the specified file or folder.

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.