As a Newbie I have spent some time trying to find out about the "out_attrib" when using the DIR statement (ref. FB manual : https://www.freebasic.net/wiki/wikka.php?wakka=KeyPgDir)
I think that the manual is a bit thin on the information on the File Attributes return values of "out_attrib" when describing the use of DIR.
After some experimentation I have compiled a list of the return values for the six most basics attributes and their combinations , that is for :
"File" , "Directory" , "Archived" , "System" , "Hidden" and "Read-only" .
Here is the list :
out_attrib :
0 = &h00 = File
1 = &h01 = File + Read-only
2 = &h02 = File + Hidden
3 = &h03 = File + Read-only + Hidden
4 = &h04 = File + System
5 = &h05 = File + System + Read-only
6 = &h06 = File + System + Hidden
7 = &h07 = File + System + Hidden + Read-only
16 = &h10 = Directory
17 = &h11 = Directory + Read-only
18 = &h12 = Directory + Hidden
19 = &h13 = Directory + Read-only + Hidden
20 = &h14 = Directory + System
21 = &h15 = Directory + System + Read-only
22 = &h16 = Directory + System + Hidden
23 = &h17 = Directory + System + Hidden + Read-only
32 = &h20 = File + archived
33 = &h21 = File + archived + Read-only
34 = &h22 = File + archived + Hidden
35 = &h23 = File + archived + Read-only + Hidden
36 = &h24 = File + archived + System
37 = &h25 = File + archived + System + Read-only
38 = &h26 = File + archived + System + Hidden
39 = &h27 = File + archived + System + Hidden + Read-only
48 = &h30 = Directory + archived
49 = &h31 = Directory + archived + Read-only
50 = &h32 = Directory + archived + Hidden
51 = &h33 = Directory + archived + Read-only + Hidden
52 = &h34 = Directory + archived + System
53 = &h35 = Directory + archived + System + Read-only
54 = &h36 = Directory + archived + System + Hidden
55 = &h37 = Directory + archived + System + Hidden + Read-only
These six "out_attrib" values is with reference to the use of DIR as shown in example here that I made using manual example as basis for modification (Note : code will only work for files and directories having only the 6 attributes desribed) :
Code: Select all
'' Heavily modified manual example of using DIR function and retrieving attributes
'' Made by freebasic.net forum member "Trinity"
' -----------------------------------------------------
#include "fbgfx.bi"
Using FB ' namespace
dim as integer W,H
screeninfo W,H 'monitor dimensions
W=W-24 : H=H-24
screenres W,H,,, GFX_NO_FRAME ' temp
Width w\8, H\16 '' Use 8*16 font
' -----------------------------------------------------
Print " Dir = "; : Print CurDir : Print
' -----------------------------------------------------
#include "dir.bi" '' provides constants to match the attributes against
'' set input attribute mask to allow files that are normal, hidden, system or directory
Const attrib_mask = fbNormal Or fbHidden Or fbSystem Or fbDirectory ' = &h37
Dim As UInteger out_attr,sortattrib,printpause '' unsigned integers , out_attr hold retrieved attributes
Dim As String fname, ISfbArchive, ISfileOrDir '' fname for file/directory name return
Dim As Integer filecount, dircount,t
Dim as string attributenames(1 to 7)
printpause=20 ' set number of records to show before print pause
Restore AttributeData : For t=1 to 7 : read attributenames(t) : next t ' Reading attribute name data
AttributeData:
Data "fbReadOnly","fbHidden","fbReadOnly , fbHidden","fbSystem","fbSystem , fbReadOnly","fbSystem , fbHidden","fbSystem , fbReadOnly , fbHidden" ' Attribute name data
fname = Dir("*.*", attrib_mask, out_attr) '' Get first file name/attributes, according to supplied file spec and attribute mask
Print "File listing in " & CurDir & ":"
Do Until Len(fname) = 0 '' loop until Dir returns empty string
sortattrib=out_attr
If (fname <> ".") And (fname <> "..") Then '' ignore current and parent directory entries
if sortattrib>=32 then ISfbArchive="fbArchive" : sortattrib = sortattrib-32 else ISfbArchive="" ' Checks if Archive or not
if sortattrib>=16 then ISfileOrDir="Directory" : dircount+=1 : sortattrib = sortattrib-16 else ISfileOrDir="file" : filecount += 1 ' Checks if directory or file
Print fname; : locate ,40 : Print ;ISfileOrDir & right(" ",6*abs(ISfileOrDir="file")) ; ' Prints if Fname is of type file or directory
locate ,50 : If sortattrib=0 then Print ;ISfbArchive else print ;ISfbArchive & right(" , ",3*abs(ISfbArchive<>""))& attributenames(sortattrib) ' prints attributes of Fname
if (filecount+dircount) mod printpause=0 then SLEEP : While Inkey <> "": Wend ' Print pause if
End If
fname = Dir(out_attr) '' find next name/attributes
Loop
Print
Print "Found " & filecount & " files and " & dircount & " subdirs"
SLEEP