Page 1 of 1

How to get multiple file attributes

Posted: Mon May 05, 2003 7:23 am
by Fangbeast
In the PB help, it explains how to return just one attribute using the & symbol. How do you return multiple attributes with pb this way?

I use the below code to return a single attribute from a file but if a file has more than one attribute set; or none; I don't know how to do it.

And I set a text mask for the user as you can see:)

Code: Select all


Mattribute   = DirectoryEntryAttributes()

If Mattribute & #PB_FileSystem_Normal         : Attributes.s = "-----"
ElseIf Mattribute & #PB_FileSystem_ReadOnly   : Attributes.s = "R----"
ElseIf Mattribute & #PB_FileSystem_Archive    : Attributes.s = "-A---"
ElseIf Mattribute & #PB_FileSystem_System     : Attributes.s = "--S--"
ElseIf Mattribute & #PB_FileSystem_Hidden     : Attributes.s = "---H-"
ElseIf Mattribute & #PB_FileSystem_Compressed : Attributes.s = "----C"
EndIf


Re: How to get multiple file attributes

Posted: Mon May 05, 2003 8:06 am
by PB
You were already close, but you were not testing for multiple flags (due to ElseIf). :)
Here's a very quick'n'dirty API example (there's definitely better ways):

Code: Select all

Procedure.s GetAttributes(file$)
  r=GetFileAttributes_(file$)
  If r & #FILE_ATTRIBUTE_ARCHIVE : a$+"A" : Else : a$+"-" : EndIf
  If r & #FILE_ATTRIBUTE_COMPRESSED : a$+"C" : Else : a$+"-" : EndIf
  If r & #FILE_ATTRIBUTE_DIRECTORY : a$+"D" : Else : a$+"-" : EndIf
  If r & #FILE_ATTRIBUTE_HIDDEN : a$+"H" : Else : a$+"-" : EndIf
  If r & #FILE_ATTRIBUTE_READONLY : a$+"R" : Else : a$+"-" : EndIf
  If r & #FILE_ATTRIBUTE_SYSTEM : a$+"S" : Else : a$+"-" : EndIf
  ProcedureReturn a$
EndProcedure
;
Debug GetAttributes("c:\autoexec.bat")
BTW, there's no "normal" flag up there because mask$ would simply be "-----" for such a file.

:):)

Posted: Mon May 05, 2003 8:17 am
by Fangbeast
I work on the principle of plugin technology. If yours works and mine doesn't, I plug yours in and worry about the "better way" later. (Much later) :D :evil: :roll: :D

Been adding (plugging in) bits and pieces for a dumb file manager that I want to test for other programs. Fun program so far:)

Thanks PB.