File attributes are specified numerically: Read-Only = 1, Hidden = 2, System =
4, and Archive = 32. So, to set the Hidden and System attributes for a file, the
Attrib parameter would be set to 6 (or 2 + 4). To read a file??™s attributes, the
same constants are used, but only individually. For example, to see whether
a file had, say, the System attribute turned on, you would use this statement:
If GetAttributes("c:\somefile.txt",4) = True Then Msgbox "This is a system
File."
And the routines are:
Function GetAttributes(Filename, Attrib)
Set FileObject = CreateObject("Scripting.FileSystemObject")
Set FileHandle = FileObject.GetFile(Filename)
If FileHandle.Attributes And Attrib Then
GetAttributes = True
Object References | 529
Scripting and
Automation
Else
GetAttributes = False
End If
End Function
Sub SetAttributes(Filename, Attrib)
Set FileObject = CreateObject("Scripting.FileSystemObject")
Set FileHandle = FileObject.GetFile(Filename)
FileHandle.Attributes = Attrib
End Sub
The following four functions are used to obtain the locations of special Windows
folders, or, in the case of GetTempFilename, to obtain the full path and
filename of a newly generated temporary filename. (The file returned by
GetTempFilename is guaranteed not to exist, so you can use it for the purposes
of temporary storage without fear of conflicting with another open
application.)
For example, to get the full path of the current user??™s Desktop folder, you
would use something like MyDesktopFolder = GetSpecialFolder("Desktop").
Pages:
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736