Post by Rod on Feb 5, 2021 10:39:55 GMT -5
Walt's work on giving us some API tools to negotiate our drives prompted me to go back and look at the Files command. I see from the LBPE we have lost some of the graphic resources. If you look at the Files tutorial you will see this is missing.
Now it clearly shows how we should think about the info$() matrix and it added a huge amount of clarity for me. But when we descend into coding it is easy to lose that clarity.
I have a habit of putting meaningful names to array() index values, so I kinda declare them at the head of the program and then I find it much easier to write the correct expression for info$()
This code uses named indexes for the three sections contained in info$() The header that tells us about the directory, the file section itself and finally the sub directory section.
Now it clearly shows how we should think about the info$() matrix and it added a huge amount of clarity for me. But when we descend into coding it is easy to lose that clarity.
I have a habit of putting meaningful names to array() index values, so I kinda declare them at the head of the program and then I find it much easier to write the correct expression for info$()
This code uses named indexes for the three sections contained in info$() The header that tells us about the directory, the file section itself and finally the sub directory section.
dim info$(10, 10)
'set up some meaningful index names for accessing the info$() array
'first info about the directory we are looking at, be it root or sub
dFiles=0 'number of files in the directory
dSubs=1 'number of subs in the directory
drive=2 'drive name
path=3 'path name
dIndex=0 'index to directory info
'now info about each file name,size,date,attributes
fName=0
fSize=1
fDate=2
fAttr=3
fIndex=1 'which file number we are looking at 1 - N
'now info about subs in the directory
sPath=0
sName=1
sIndex=0
'first fill the info$() array with data about the directory
'first time in we are giving it the drive name c:\ for example
'so we will get the root directory info. Be aware that c:
'on its own will get the current working directory info.
files "c:\", info$()
'now print the directory info
print info$(dIndex,drive);info$(dIndex,path);"No files ";info$(dIndex,dFiles);" Number of subs ";info$(dIndex,dSubs)
'fIndex is correctly set at 1 but we must set sIndex depending on the number of files found
sIndex=val(info$(dIndex,dFiles))+1
'now print the sub directory list. just print first 5
for i= sIndex to sIndex+5
print info$(i,sPath)
next
'now print the file list in this directory. just print first 5
for i= fIndex to fIndex+5
print info$(i,fName);info$(i,fSize);info$(i,fDate);info$(i,fAttr)
next
wait