[Coco] File Size
William Astle
lost at l-w.ca
Tue Feb 14 10:58:47 EST 2023
On 2023-02-14 08:52, Allen Huffman via Coco wrote:
> I was just looking in to this, and I didn’t see any way to do with a command, but I did figure out how to manually do it by parsing the directory track (track 17).
>
> Basically you have to read track 17 and go through the directory entries. When you find the one that matches the file you want to know about, that entry will have the start granule number and how many bytes are in the last sector of the file. You then go to the gradual list (68 bytes of a sector) and look for the one that matches the start granule. If the directory say it starts at gran 10, you look at byte 10 and that tell you the next granule in the list, and so on. The last granule has some high bits set, telling you that’s the last of the file, and the rest of those bits tell you how many sectors are used. You add up how many full granules you scanned, plus how many sectors it says are at the end, with the “bytes in the last sector” value from the directory entry.
You can also "cheat" it by opening the file in "R" (or "D") mode with a
1 byte record size, then use LOF() to get the number of records, then
close the file again.
OPEN "R",#1,"FILE.EXT",1
L=LOF(1)
CLOSE #1
Which basically makes the Disk Basic ROM do exactly what Allen described.
More information about the Coco
mailing list