Javascript FileSystemObject (FSO) provides Attributes property that can be accessed through file object or folder object returned by the GetFile method or GetFolder methods. Both these methods allow the access to Attributes property that returns the attributes of the specified file or folder. Attributes property provides the functionality to get or set the attributes of the specified file or folder for example: read-only property, hidden file property, System files property etc.
Syntax for Javascript FSO Attributes property
fileObj.Attributes // or folderObj.Attributes
Both above syntaxes show the way of using the file object and folder object to access the Attributes property. GetFile method returns the file object and GetFolder method returns the folder object that can be used to access the Attributes property associated with the specified file or folder. You can the Attributes property to get or set the attribute properties of file or folder. Following are the value that can be retrieved or assigned to the attributes property:
0 = value for normal file
1 = value for read-only file
2 = value for hidden file
4 = value for System file
16 = value for Folder
32 = value for modified file
1024 = value for shortcut
2048 = value for compressed file or folder
Example of Javascript FSO Attributes 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 Attribute: </b>" + fileObj.Attributes);
document.write("<br />");
// object created for folder object returned by GetFolder method
var folderObj = fso.GetFolder("C:\\Temp\\myFolder");
document.write("<b>Folder Attribute: </b>" + folderObj.Attributes);
document.write("<br />");
fso = null;
// Output:
// File Attribute: 32
// Folder Attribute: 16
</script>
Continue to next tutorial: Javascript FSO DateCreated Property to learn how to get the creation date of the specified file or folder.