Javascript FileSystemObject (FSO) GetBaseName method provides the functionality to get the base of the specified file or folder. If path specified in the GetBaseName method contains file name at the end then it returns the name of the specified file except its extension and absolute path. If path specified in the GetBaseName method end with folder name then it returns the name of the folder at the end of the path. 

Syntax for Javascript FSO GetBaseName Method

fso.GetBaseName( Path );

As shown in the above syntax of FSO GetBaseName method, it accepts only one parameter as path of any file or folder whose base name is to be retrieved.

Example of FSO GetBaseName Method

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

    // returns the base name of the specified file
    var fbaseName = fso.GetBaseName("C:\\Temp\\myFolder\\file.txt");
    document.write(fbaseName);
    document.write("<br />");

    // returns the base name of the specified folder
    fbaseName = fso.GetBaseName("C:\\Temp\\myFolder");
    document.write(fbaseName);
    document.write("<br />");

    fso = null;

    // Output: 
    // file 
    // myFolder
</script>

Continue to next tutorial: Javascript FileSystemObject GetDrive method with Properties to learn how to access the specified drive.

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.