• Welcome to Jose's Read Only Forum 2023.
 

IFolder.Attributes Property

Started by José Roca, July 14, 2008, 02:08:26 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

José Roca



The following examples illustrate the use of the Attributes property with an IFolder object:


#INCLUDE "windows.inc"
#INCLUDE "scrrun.inc"

DIM fso AS IFileSystem
DIM pFolder AS IFolder
DIM nAttr AS LONG
DIM strAttr AS STRING

' Create an instance of the FileSystemObject
fso = NEWCOM "Scripting.FileSystemObject"
' Get a reference to the IFolder interface
pFolder = fso.GetFolder(UCODE$("C:\MyFolder\"))
' Get and display the attributes
nAttr = pFolder.Attributes
IF nAttr = 0 THEN strAttr = "[Normal]"
IF (nAttr AND 1) = 1 THEN strAttr += "[ReadOnly]"
IF (nAttr AND 2) = 2 THEN strAttr += "[Hidden]"
IF (nAttr AND 4) = 4 THEN strAttr += "[System]"
IF (nAttr AND 8) = 8 THEN strAttr += "[Volume]"
IF (nAttr AND 16) = 16 THEN strAttr += "[Directory]"
IF (nAttr AND 32) = 32 THEN strAttr += "[Archive]"
IF (nAttr AND 1024) = 1024 THEN strAttr += "[Alias]"
IF (nAttr AND 2048) = 2048 THEN strAttr += "[Compressed]"
MSGBOX "Folder attributes: " & strAttr



DIM fso AS IFileSystem
DIM pFolder AS IFolder
DIM nAttr AS LONG
DIM strAttr AS STRING

' Create an instance of the FileSystemObject
fso = NEWCOM "Scripting.FileSystemObject"
' Get a reference to the IFolder interface
pFolder = fso.GetFolder(UCODE$("C:\MyFolder\"))
' Get and display the attributes
nAttr = pFolder.Attributes
' Set the attribute
pFolder.Attributes = %FileAttribute_ReadOnly
IF OBJRESULT = %S_OK THEN
   PRINT "Attributes set"
ELSE
   PRINT "Error &H" & HEX$(OBJRESULT) & " setting the attribute"
END IF