Directory listing question using FSRW 2.6
Don M
Posts: 1,652
Here is the code that I'm using:
I have 31 files on the sd card. When doing a directory listing the listing starts out fairly fast but then gradually slows down as the listing progresses. Anyone else ever notice this? what might be the bottle neck in this?
In case you're wondering- yes I have tried many different cards. It's not the cards. Is there a buffer somewhere that gets bogged down?
pub SD_Directory | num_files, j, rslt rslt := \sd_mount if rslt < 0 return num_files := 0 sd.opendir slave.str(@sdfiledir1) repeat while 0 == sd.nextfile(@tbuf) num_files ++ repeat j from 1 to num_files bytefill(@tbuf, 0, 20) sd.opendir repeat j sd.nextfile(@tbuf) sd[ 1 ].popen(@tbuf, "r") slave.str(@tbuf) repeat 15 - strsize(@tbuf) slave.tx(" ") slave.dec(sd[ 1 ].get_filesize) sd[ 1 ].pclose slave.tx(13) slave.tx(10) slave.str(string("Number of files: ")) slave.dec(num_files) slave.tx(13) slave.tx(10) sd.pclose sd_unmount
I have 31 files on the sd card. When doing a directory listing the listing starts out fairly fast but then gradually slows down as the listing progresses. Anyone else ever notice this? what might be the bottle neck in this?
In case you're wondering- yes I have tried many different cards. It's not the cards. Is there a buffer somewhere that gets bogged down?
Comments
It appears, invoking fsrw.nextfile(buffer) copies the 8.3 file name to the buffer argument. If no file is found then fsrw.nextfile(buffer) returns -1. The directory listing in the original posting can be simplified with a single repeat until. Instead of first finding the number of files keep incrementing a counting until fsrw.nextfile(buffer) returns -1. On each iteration that returns 0, either send the file name to the terminal, process the file name, or buffer the files name(s) for later processing.
Although it would be nice to have the filesize...
What are you doing with "b"? I see it starts out as "0" and you increment it by 13 through the repeat loop and if it equals 78 you do what? Send a CR? Are you counting characters?
That is what the original code I posted above does. It uses 2 iterations of FSRW. One to read the filenames and the other to get the filesize of the filename. It really slows down if you have a number of files to list.
I think your code could be sped up a little bit by rewriting it as follows: This will still slow down as you proceed through the directory because popen will scan through the directory looking for the file each time. It takes longer to open a file that's located further in the directory. As I mentioned in my previous post, you could speed this up by modifying nextfile, or adding a new method to FSRW that returns both the filename and filesize.
I see now. You are listing them in a block sideways. When you get to 78 you start a new line.
Dave- That works 100% faster. Thanks for your help.
But for some reason I can't get the first line to work right. I tried changing the b := b + 21 and the if b == 42 statements but can't figure out why. Also tried initializing b to 1. The filename, space, 8 digit filesize and space equals 21
Here's what I get:
What am I doing wrong?