Javascript FileSystemObject (FSO) consists of FolderExists method that provides the functionality to check whether the specified folder exists at the given location or not. FSO FolderExists method returns the Boolean value i.e. true or false based on the existence of the specified folder name. FolderExists method returns true if the folder exits at the specified location and returns false if folder or location does not exist. Javascript FolderExists method is very useful while creating or deleting the folders at client side coz if folder does not exist while deletion action then it throws an error and stops the execution of rest of javascript code placed after that code line. 

Syntax for Javascript FSO FolderExists Method

fso.FolderExists( folderSpec ); 

As shown above FSO FolderExists method accepts only one parameter as folder name along with its path. It checks the folder at the specified location and returns the Boolean value accordingly.

Example for FSO FolderExists Method

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

    // if condition to check whether the specified folder exists or not.
    if (fso.FolderExists("C:\\Temp\\myFolder")) {
        document.write("myFolder exists.");
    }
    else {
        document.write("myFolder does not exist.");
    }

    fso = null;
</script>

Continue to next tutorial: Javascript FSO GetAbsolutePathName Method to learn how to get the absolute path to the specified location.

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.