-
Another place that bit-wise operators and mappings frequent arise is with file attributes: From Help (Attributes)
[vba]
Option Explicit
'Normal 0 Normal file. No attributes are set.
'ReadOnly 1 Read-only file. Attribute is read/write.
'Hidden 2 Hidden file. Attribute is read/write.
'System 4 System file. Attribute is read/write.
'Volume 8 Disk drive volume label. Attribute is read-only.
'Directory 16 Folder or directory. Attribute is read-only.
'Archive 32 File has changed since last backup. Attribute is read/write.
'Alias 64 Link or shortcut. Attribute is read-only.
'Compressed 128 Compressed file. Attribute is read-only.
Sub SetClearArchiveBit()
Dim oFSO As Object, oFile As Object
Dim iAns As Long, iAttributes As Long, iHSA As Long
Dim sFileName As String
sFileName = Application.GetOpenFilename("Any File (*.*), *.*")
If sFileName = "False" Then Exit Sub
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFile = oFSO.GetFile(oFSO.GetFileName(sFileName))
iHSA = vbHidden Or vbSystem Or vbArchive
If (oFile.Attributes And vbNormal) Then MsgBox "Normal"
If (oFile.Attributes And vbReadOnly) Then MsgBox "ReadOnly"
If (oFile.Attributes And vbHidden) Then MsgBox "Hidden"
If (oFile.Attributes And vbSystem) Then MsgBox "System"
If (oFile.Attributes And vbVolume) Then MsgBox "Volume Label"
If (oFile.Attributes And vbDirectory) Then MsgBox "Directory"
If (oFile.Attributes And vbArchive) Then MsgBox "Archive"
If (oFile.Attributes And vbAlias) Then MsgBox "Alias"
If (oFile.Attributes And 128) Then MsgBox "Compressed"
'desktop.ini
If (oFile.Attributes And iHSA) Then MsgBox "The Hidden, System, and Archive bits are set"
If (oFile.Attributes And vbArchive) Then
iAns = MsgBox("The Archive bit is set, do you want to clear it?", vbYesNo, "Set/Clear Archive Bit")
If iAns = vbYes Then
oFile.Attributes = oFile.Attributes And Not vbArchive
MsgBox "Archive bit is cleared."
Else
MsgBox "Archive bit remains set."
End If
Else
iAns = MsgBox("The Archive bit is not set. Do you want to set it?", vbYesNo, "Set/Clear Archive Bit")
If iAns = vbYes Then
oFile.Attributes = oFile.Attributes Or vbArchive
MsgBox "Archive bit is set."
Else
MsgBox "Archive bit remains clear."
End If
End If
End Sub
[/vba]
Paul
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules