Files and folder
Small Basic uses arrays to provide access to your filing system. I.e. to list files and folders on the storage media on your PC. Thus if you want to know what files you have saved in a particular folder, or you want to know what folders exist then Small Basic can tell you but only in the form of an array. Look at the example on the left.
Program.Directory returns the folder where the program is running. This is why I always recommend saving before you run a program – you know where you saved it and can check the information that Small Basic is returning to you!
File.GetFiles( path ) gets all the files that are in the folder specified by ‘path’, i.e. the folder where you saved the program. Even if it is just one file it will retuned in an array.
Array.GetItemCount( array ) tells you how many file there are so that the main body of the program can simply loop through the array, displaying each one.
If you have run this program, you will see that Small Basic returns the full filename including the path. It should be possible to remove the path bit using one of the Text object methods.
As well as being able to return an array of files, you can also ask Small Basic to return a list of sub-folders in a specific folder. However, if your folder doesn’t contain any sub-folders this method will return an empty simple variable as the result (not ‘FAILED” as in the intellisence panel). Any program written to do this must accommodate this possibility.