Javascript FileSystemObject (FSO) GetExtensionName method provides the functionality to retrieve the extension of the specified file in the path. GetExtensionName method extracts the name of the extension that exists after the “.” symbol with file name. If path specified in the FSO GetExtensionName method does not contain any file name then it returns the empty string. 

Syntax for Javascript FSO GetExtensionName method

fso.GetExtensionName( Path );

As shown in the above syntax of FSO GetExtensionName method it accepts only one parameter as path of the file whose extension is to be retrieved.

Example of FSO GetExtensionName method

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

    // returns the file extension from the specified path
    var fileExt = fso.GetExtensionName("c:\\Temp\\myFolder\\file.txt");
    document.write(fileExt);
    document.write("<br />");

    fso = null;

    // Output: 
    // txt
</script>

Continue to next tutorial: Javascript FSO GetFile Method to learn how get the file information.

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.