The following code illustrates the use of the
Attributes property with a file:
JScript
function ToggleArchiveBit(filespec)
{
var fso, f, r, s;
fso = new ActiveXObject("Scripting.FileSystemObject");
f = fso.GetFile(filespec)
if (f.attributes & 32)
{
f.attributes = f.attributes - 32;
s = "Archive bit is cleared.";
}
else
{
f.attributes = f.attributes + 32;
s = "Archive bit is set.";
}
return(s);
}
VBScript
Function ToggleArchiveBit(filespec)
Dim fso, f
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFile(filespec)
If f.attributes and 32 Then
f.attributes = f.attributes - 32
ToggleArchiveBit = "Archive bit is cleared."
Else
f.attributes = f.attributes + 32
ToggleArchiveBit = "Archive bit is set."
End If
End Function
PowerBASIC
FUNCTION ToggleArchiveBit (BYVAL filespec AS STRING) AS STRING
LOCAL fso AS IFileSystem
LOCAL f AS IFile
Local attr AS LONG
fso = NEWCOM "Scripting.FileSystemObject"
f = fso.GetFile(UCODE$(filespec))
attr = f.Attributes
IF (attr AND 32) THEN
attr = attr - 32
FUNCTION = "Archive bit is cleared."
ELSE
attr = attr + 32
FUNCTION = "Archive bit is set."
END IF
END FUNCTION