VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Get and Set attributes of a file

by themaxx (2 Submissions)
Category: Files/File Controls/Input/Output
Compatability: Visual Basic 3.0
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (2 Votes)

this is an easy code to get and set any file's attibutes (system, hidden, read-only,...) throught the vb function getatr and setattr

Inputs
- ofthis (string): the full filename - tothis (long): the number associated with the attr. the correct values are in the code ex: 44 = archive (32) + volume (8) + system (4)
Code Returns
getattributes returns a string that contains the attributes setattributes returns a boolean : true = ok, false = error

Rate Get and Set attributes of a file

'*** Get and Set attributes of o file ***********
'*                       *
'************************************************
Public Function GetAttributes(OfThis As String) As String
Dim Tmp As VbFileAttribute
Tmp = GetAttr(OfThis)
If Tmp >= vbAlias Then '64
  GetAttributes = GetAttributes & " Alias"
  Tmp = Tmp - vbAlias
End If
If Tmp >= vbArchive Then ' 32
  GetAttributes = GetAttributes & " Archive"
  Tmp = Tmp - vbArchive
End If
If Tmp >= vbDirectory Then '16
  GetAttributes = GetAttributes & " directory"
  Tmp = Tmp - vbDirectory
End If
If Tmp >= vbVolume Then '8
  GetAttributes = GetAttributes & " volume"
  Tmp = Tmp - vbVolume
  End If
If Tmp >= vbSystem Then '4
  GetAttributes = GetAttributes & " System"
  Tmp = Tmp - vbSystem
End If
If Tmp >= vbHidden Then '2
  GetAttributes = GetAttributes & " Hidden"
  Tmp = Tmp - vbHidden
End If
If Tmp >= vbReadOnly Then '1
  GetAttributes = GetAttributes & " Read Only"
  Tmp = Tmp - vbReadOnly
End If
If Tmp = vbNormal Then '0
  GetAttributes = GetAttributes & " Normal"
  Tmp = Tmp - vbNormal
End If

End Function
Public Function SetAttributes(OfThis As String, ByVal ToThis As VbFileAttribute) As Boolean
 SetAttributes = True
 On Error GoTo errh
 SetAttr OfThis, ToThis
 GoTo fin
errh:
 SetAttributes = False
 Err.Clear
 Exit Function
fin:
 SetAttributes = True
End Function

Download this snippet    Add to My Saved Code

Get and Set attributes of a file Comments

No comments have been posted about Get and Set attributes of a file. Why not be the first to post a comment about Get and Set attributes of a file.

Post your comment

Subject:
Message:
0/1000 characters