Author Topic: IFile.Attributes Property  (Read 3043 times)

0 Members and 1 Guest are viewing this topic.

Online José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2517
  • User-Rate: +209/-0
  • Gender: Male
IFile.Attributes Property
« on: July 14, 2008, 04:22:57 AM »

The following code illustrates the use of the Attributes property with a file:

JScript

Code: [Select]
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

Code: [Select]
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

Code: [Select]
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