VB icon

Get and Set attributes of a file

Submitted on: 1/23/2015 3:34:00 AM
By: themaxx (from psc cd)  
Level: Beginner
User Rating: By 2 Users
Compatibility: VB 4.0 (16-bit), VB 4.0 (32-bit), VB 5.0, VB 6.0, VB Script, ASP (Active Server Pages) , VBA MS Access, VBA MS Excel
Views: 1033
     this is an easy code to get and set any file's attibutes (system, hidden, read-only,...) throught the vb function getatr and setattr
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
' Name: Get and Set attributes of a file
' Description:this is an easy code to get and set any file's attibutes (system, hidden, read-only,...) throught the vb function getatr and setattr
' By: themaxx (from psc cd)
' 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)
' Returns:getattributes returns a string that contains the attributes
setattributes returns a boolean : true = ok, false = error

'*** 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
 SetAttributes = False
 Exit Function
 SetAttributes = True
End Function

Other 1 submission(s) by this author


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)

Other User Comments

 There are no comments on this submission.

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)

To post feedback, first please login.