Home > How-To Library > File/Folders Handling
How to Read and Modify the attributes of a file
**************************************************************** * © 2007 CodeItBetter http://www.codeitbetter.com * * This notice MUST stay intact for legal use * **************************************************************** '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
If you would like to submit your code here please us. Do not forget to mention your name. We are always thankful to each and everyone of you who submitted their code here.