I'm attempting to obtain the size of a disk file in bytes before it is processed.
Unfortunately my knowledge of Commodore DOS is still quite poor.
Apart from opening a file and reading it byte by byte and keeping a counter until EOF is reached, is there a quicker way to get the exact size in bytes?
Thanks
Richard
Obtaining the size of a file on disk
Moderator: Moderators
- Mike
- Herr VC
- Posts: 4841
- Joined: Wed Dec 01, 2004 1:57 pm
- Location: Munich, Germany
- Occupation: electrical engineer
Re: Obtaining the size of a file on disk
There exists a faster method, but that critically depends on knowledge built into the program about the directory, and sector-link structure, specific to 1541/1571/1581, etc.
You would:
- extract the start track/sector of the file from the directory entry,
- load the sector from disc,
- add 254 to file length if a chains another sector,
- otherwise add the bytes indicated if it is the last sector.
This still requires the drive to fetch all sector data from disc, however the transfers from drive to computer are minimized.
I'll take a look into a CBM DOS whether the knowledge about the dir structure could be amended - i.e. if one can read the S/T data of the first block from the drive after a regular file open.
You would:
- extract the start track/sector of the file from the directory entry,
- load the sector from disc,
- add 254 to file length if a chains another sector,
- otherwise add the bytes indicated if it is the last sector.
This still requires the drive to fetch all sector data from disc, however the transfers from drive to computer are minimized.
I'll take a look into a CBM DOS whether the knowledge about the dir structure could be amended - i.e. if one can read the S/T data of the first block from the drive after a regular file open.
Re: Obtaining the size of a file on disk
Add the bytes -2 as the sector data here points to the last byte used in this sector, this includes the first two link bytes - that confused me when I made my first attempts to read files from disk.- otherwise add the bytes indicated if it is the last sector.
Other than that this is exactly the procedure I follow in BasEdit's ShowDirectory routine for diskimages
Of course on the PC this is lightning fast as opposed to read a lot of sectors on the real hardware...