You need to keep the array one dimensional to make it easier to navigate.
I threw together an example of how to do it (I assume you're using Darkbasic Pro since you were working with user defined types).
` Define the type
type Files
Computer as byte ` Computer Number 1=Local
Directory as string ` Directory Name
FileType as byte ` 1=Directory 2=File
File as string ` Filename
Size as integer ` File Size (in bytes)
Date as string ` Creation Date
endtype
` Dimensionalize the array
dim File(100) as Files
` The directory "Images" located in the root directory
File(0).Computer=1
File(0).Directory=""
File(0).FileType=1
File(0).File="Images"
File(0).Size=0
File(0).Date="10/6/2006"
` A file called "info.txt" located in the root directory
File(1).Computer=1
File(1).Directory=""
File(1).FileType=2
File(1).File="Info.txt"
File(1).Size=1000
File(1).Date="5/20/2006"
` A directory called "bmp" within the "Images" directory
File(2).Computer=1
File(2).Directory="Images"
File(2).FileType=1
File(2).File="bmp"
File(2).Size=0
File(2).Date="10/6/2006"
` A directory called "old" within the "Images" directory
File(3).Computer=1
File(3).Directory="Images"
File(3).FileType=1
File(3).File="old"
File(3).Size=0
File(3).Date="10/6/2006"
` A file called "test.bmp" within the "bmp" directory
File(4).Computer=1
File(4).Directory="bmp"
File(4).FileType=2
File(4).File="test.bmp"
File(4).Size=300420
File(4).Date="10/6/2006"
` A directory called "jpeg" within the "Images" directory
File(5).Computer=1
File(5).Directory="Images"
File(5).FileType=1
File(5).File="jpeg"
File(5).Size=0
File(5).Date="10/6/2006"
` A file called "test.exe" located in the root directory
File(6).Computer=1
File(6).Directory=""
File(6).FileType=2
File(6).File="Test.exe"
File(6).Size=1400000
File(6).Date="10/1/2006"
` A file called "background.png" located in the root directory
File(7).Computer=1
File(7).Directory=""
File(7).FileType=2
File(7).File="background.png"
File(7).Size=154600
File(7).Date="09/6/2006"
` Make MaxFiles = total records in the array
MaxFiles=array count(File())
` Set the variables (change CDirectory to see other directories)
CDirectory$=""
FileCount=0
FileSize=0
DirectoryCount=0
BytesFree=178654320
` Print files or directories located in current directory
for t=0 to MaxFiles
` Check if the Directory = the current directory (and is a valid filetype)
if File(t).Directory=CDirectory$ and File(t).FileType>0
` Print the file/directory in that directory
print File(t).File+" ";
` Check to see if it's a directory or a file and increase count
if File(t).FileType=1
print "< DIR >";
inc DirectoryCount
else
print str$(File(t).Size);
inc FileCount
endif
` Print the file date
print " "+File(t).Date
` Add size to total size
inc FileSize,File(t).Size
endif
next t
` Print totals
print ""
print str$(FileCount)+" File(s) "+str$(FileSize)+" bytes"
print str$(DirectoryCount)+" Dir(s) "+str$(BytesFree)
wait key
The above code uses "print" so it may look a bit funny (file sizes and date won't be lined up) but everything you need is right there.
The UDT is like this:
type Files
Computer as byte ` Computer Number 1=Local
Directory as string ` Directory Name
FileType as byte ` 1=Directory 2=File
File as string ` Filename
Size as integer ` File Size (in bytes)
Date as string ` Creation Date
endtype
"Computer" I added because you had it.
"Directory" is what directory the file is located in.
"FileType" determines if the file is a directory (1) or a file (2)
"File" is the actual name of the file. This can be either a new directory name or an actual file. You can use this to determine if a directory exists (with filetype being a 1). Once the current directory is changed to this filename any files/directories with that same name as defined in "Directory" will be shown.
"Size" is the file size (doesn't matter if it's a directory)
"Date" is the file date
The program starts as the CDirectory$=nothing which will show all files with nothing as the directory. There's no need to name it "root" because technically if you're in the root directory you're not really in any directory. If you change it to "Images" (it's case sensitive right now so don't forget the highercase "I") and you'll see all the files within the "Images" directory.
To be able to move back one directory you just need to keep a variable (like OldDirectory$) to store the last directory before changing to the new one.
BytesFree is just a variable to store the space left on the drive. This can be made better by adding a new variable to store the hd size and make BytesFree = hd size then go through all files subtracting the file size of each file from the BytesFree variable.
If you have any questions ask away.