File Attribute Demo 2
This demo illustrates how to programmatically determine what attributes a given file has.
Output:
The Attributes property: 32
File is not Read-only
File is not a hidden file
File is not a system file
File is not a disk drive volumn label
File is not a directory
File has the Archive bit set
File is not a link
File is not not compressed
The Source Code:
<%
Sub ListAttributes(strFileName)
'Create an instance of the FileSystemObject
Dim objFSO, objFile
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
'Use the GetFile method to get information on a file
Set objFile = objFSO.GetFile(strFileName)
Response.Write "The <code>Attributes</code> property: " & objFile.Attributes & "<p>"
'List out its properties:
if objFile.Attributes = 0 then
Response.Write "No Attributes Set..."
Else
If (objFile.Attributes AND 1) > 0 then
Response.Write "File is Read-only<br>"
Else
Response.Write "File is <b>not</b> Read-only<br>"
End If
If objFile.Attributes AND 2 then
Response.Write "File is a hidden file<br>"
Else
Response.Write "File is <b>not</b> a hidden file<br>"
End If
If objFile.Attributes AND 4 then
Response.Write "File is a system file<br>"
Else
Response.Write "File is <b>not</b> a system file<br>"
End If
If objFile.Attributes AND 8 then
Response.Write "File is a disk drive volumn label<br>"
Else
Response.Write "File is <b>not</b> a disk drive volumn label<br>"
End If
If objFile.Attributes AND 16 then
Response.Write "File is a directory<br>"
Else
Response.Write "File is <b>not</b> a directory<br>"
End If
If objFile.Attributes AND 32 then
Response.Write "File has the Archive bit set<br>"
Else
Response.Write "File does <b>not</b> have the Archive bit set<br>"
End If
If objFile.Attributes AND 64 then
Response.Write "File is a link<br>"
Else
Response.Write "File is <b>not</b> a link<br>"
End If
If objFile.Attributes AND 128 then
Response.Write "File is compressed<br>"
Else
Response.Write "File is <b>not</b> not compressed<br>"
End If
End If
End Sub
ListAttributes(Server.MapPath("/index.shtml"))
%>
|
[Return to the Article] |
[View Demo 1]