VB Code:
  1. ' API Method
  2.  
  3. Private Declare Function SetFileAttributes Lib "kernel32" Alias "SetFileAttributesA" (ByVal lpFileName As String, ByVal dwFileAttributes As Long) As Long
  4.  
  5. Private Const FILE_ATTRIBUTE_ARCHIVE = &H20
  6. Private Const FILE_ATTRIBUTE_COMPRESSED = &H800
  7. Private Const FILE_ATTRIBUTE_DIRECTORY = &H10
  8. Private Const FILE_ATTRIBUTE_HIDDEN = &H2
  9. Private Const FILE_ATTRIBUTE_NORMAL = &H80
  10. Private Const FILE_ATTRIBUTE_READONLY = &H1
  11. Private Const FILE_ATTRIBUTE_SYSTEM = &H4
  12. Private Const FILE_ATTRIBUTE_TEMPORARY = &H100
  13.  
  14. ' Usage (This will set file to hidden)
  15.  
  16.     Dim File as String
  17.  
  18.     File = "Path of file"
  19.  
  20.     SetFileAttributes File, FILE_ATTRIBUTE_HIDDEN
  21.  
  22.  
  23.  
  24. ' FSO Method (this examples set attributes of folder, but can be easily changed to a file)
  25.  
  26.     Dim FSO As New Scripting.FileSystemObject
  27.    
  28.     Dim F As Folder
  29.    
  30.     Set F = FSO.GetFolder(FDR)
  31.    
  32.     F.Attributes = Hidden
  33.    
  34.     Set F = Nothing
  35.    
  36.     Set FSO = Nothing