How to get multiple file attributes

Just starting out? Need help? Post your questions and find answers here.
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4792
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

How to get multiple file attributes

Post 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

Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: How to get multiple file attributes

Post 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.
Last edited by PB on Thu Sep 04, 2003 1:28 am, edited 1 time in total.
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4792
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

:):)

Post 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.
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
Post Reply