Javascript FileSystemObject (FSO) provides a Type property that can be accessed through file object or folder object returned by the GetFile or GetFolder method. Type property returns the type of the specified file or folder whether it is text document or file folder based on the specified file or folder.
Syntax for FSO Type Property
fileObj.Type // or folderObj.Type
You can use any of the above syntax to access the Type property based on the object type. GetFile method returns the file object that will return the file type as a result of Type property and GetFolder method returns the folder object that will return the folder type as a result of Type property.
Examples of Javascript FSO Type property
Example 1
File object to get the value of Type 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 Type : </b>" + fileObj.Type);
document.write("<br />");
// Output:
// File Type : Text Document
</script>
Example 2
Folder object to get the value of Type 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 Type : </b>" + folderObj.Type);
document.write("<br />");
// Output:
// Folder Type : File Folder
</script>
Continue to next tutorial: Javascript FSO Copy Method to learn how to copy a specified file or folder to the specified location.