Enumerating File Attributes

Microsoft® Windows® 2000 Scripting Guide

microsoft windows 2000 scripting guide

« Previous | Next »   

Like folders, files also have attributes that can be retrieved and configured using the FileSystemObject. Also like folders, file attributes are returned as a bitmap value. (For more information on bitmap values and how to use them, see "Managing Folder Attributes" earlier in this chapter.) File attributes can include any or all of the values shown in Table 4.6.

Table 4.6   File Attributes Used by the FileSystemObject

ConstantValueDescription
Normal0File with no attributes set.
Read-only1File can be read but cannot be modified.
Hidden2File is hidden from view in Windows Explorer or My Computer.
System4File is needed by the operating system.
Archive32File is flagged as requiring backup.
Alias64File is a shortcut to another file.
Compressed2048File has been compressed.

To retrieve the attributes of a file, use the GetFile method to bind to the file. After you have created an object reference to the file, you can use the logical AND operator to determine the file attributes. If the file does not have any attributes configured, the Attributes value will be 0.

For example, the script in Listing 4.28 binds to the file C:\FSO\ScriptLog.txt and then checks for the presence of each attribute that can be retrieved using the FileSystemObject.

Listing 4.28   Enumerating File Attributes

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 
Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFile = objFSO.GetFile("C:\FSO\ScriptLog.txt") If objFile.Attributes AND 0 Then     Wscript.Echo "No attributes set." End If If objFile.Attributes AND 1 Then     Wscript.Echo "Read-only." End If If objFile.Attributes AND 2 Then     Wscript.Echo "Hidden file." End If If objFile.Attributes AND 4 Then     Wscript.Echo "System file." End If If objFile.Attributes AND 32 Then     Wscript.Echo "Archive bit set." End If If objFile.Attributes AND 64 Then     Wscript.Echo "Link or shortcut." End If If objFile.Attributes AND 2048 Then     Wscript.Echo "Compressed file." End If

send us your feedback Send us your feedback « Previous | Next »   


Microsoft Windows 2000 Scripting Guide(c) Automating System Administration 2003
Microsoft Windows 2000 Scripting Guide(c) Automating System Administration 2003
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 635

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net