How to Read and Modify the attributes of a file
Posted on July 27, 2011
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | 'File/Folder Handling - How to Read and Modify the attributes of a file 'We need to use GetAttr and SetAttr function ' This routine also works with open files and raises an error if the file doesn't exist. Function GetAttrDescr(filename As String) As String Dim result As String, attr As Long attr = GetAttr(filename) ' GetAttr also works with directories. If attr And vbDirectory Then result = result & " Directory" If attr And vbReadOnly Then result = result & " ReadOnly" If attr And vbHidden Then result = result & " Hidden" If attr And vbSystem Then result = result & " System" If attr And vbArchive Then result = result & " Archive" ' Discard the first (extra) space. GetAttrDescr = Mid$(result, 2) End Function 'Mark a file as Archive and Read-only. filename = "d:\VS98\Temporary.Dat" SetAttr filename, vbArchive + vbReadOnly 'Change a file from hidden to visible, and vice versa. SetAttr filename, GetAttr(filename) Xor vbHidden 'You can't use the SetAttr function on open files |