convert .flags to Amiga Protection bits string

You can post your code snippets here for others to use and learn from
Post Reply
Severin
Posts: 7
Joined: Wed Oct 25, 2017 8:17 pm

convert .flags to Amiga Protection bits string

Post by Severin » Fri May 03, 2019 1:12 am

I tried many different ways to convert the .flags number returned by DirectoryItems() into a string, some of which got very silly indeed, mostly because I tried to create the string on the fly by adding the required bits as I tested for them, that was wrong, the best way I found is to remove unwanted bits from a complete string. So here is my first 'snippit', enjoy.

Code: Select all

Function P_GetBits(flags)
	Local f$ = "HSPARWED"
	If Not (flags & #FILEATTR_HIDDEN)      Then f$ = ReplaceStr(f$, "H", "-")
	If Not (flags & #FILEATTR_SCRIPT)      Then f$ = ReplaceStr(f$, "S", "-")
	If Not (flags & #FILEATTR_PURE)        Then f$ = ReplaceStr(f$, "P", "-")
	If Not (flags & #FILEATTR_ARCHIVE)     Then f$ = ReplaceStr(f$, "A", "-")
	If Not (flags & #FILEATTR_READ_USR)    Then f$ = ReplaceStr(f$, "R", "-")
	If Not (flags & #FILEATTR_WRITE_USR)   Then f$ = ReplaceStr(f$, "W", "-")
	If Not (flags & #FILEATTR_EXECUTE_USR) Then f$ = ReplaceStr(f$, "E", "-")
	If Not (flags & #FILEATTR_DELETE_USR)  Then f$ = ReplaceStr(f$, "D", "-")
	Return(f$)
EndFunction

Post Reply