Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 02:54 18 Sep 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : file sizes on colour maximite

Author Message
Yourock17
Newbie

Joined: 09/01/2015
Location: Australia
Posts: 12
Posted: 12:17am 08 Nov 2015
Copy link to clipboard 
Print this post

Hey guys, is there any way to get the size of a file on the SD card as a variable while the program is running? As an example, I am trying to make a fancy .mod player and I would like to get the length of the song currently playing. I saw the LOF() function in the manual, but am unsure of it's use. Im not sure where to start or if it's even possible. Any suggestions would help.

My firmware version is 4.01 on the Colour Maximite
 
twofingers

Guru

Joined: 02/06/2014
Location: Germany
Posts: 1629
Posted: 02:10am 08 Nov 2015
Copy link to clipboard 
Print this post

  Quote  Hey guys, is there any way to get the size of a file on the SD card as a variable while the program is running?

Yes!

A code snipped from my File Selector :


Dim errText$(17)

'0="No error"
errText$(1) ="No SD card found"
errText$(2) ="SD card is write protected"
errText$(3) ="Not enough space"
errText$(4) ="All root directory entries are taken"
errText$(5) ="Invalid filename"
errText$(6) ="Cannot find file"
errText$(7) ="Cannot find directory"
errText$(8) ="File is read only"
errText$(9) ="Cannot open file"
errText$(10)="Error reading from file"
errText$(11)="Error writing to file"
errText$(12)="Not a file"
errText$(13)="Not a directory"
errText$(14)="Directory not empty"
errText$(15)="Hardware error accessing the storage media"
errText$(16)="Flash memory write failure"
errText$(17)="Source and destination are the same!" 'MMBasic bug

Function FileSize N$
Local OpenError
If n$<>".." Then
Option Error Continue
Open N$ For input As #10
OpenError = MM.Errno
Option Error Abort
If OpenError Then
StatusMsg ("OpenError: "+errText$(OpenError))
FileSize=0
Else
FileSize=Lof(10)
Close 10
EndIf
Else
FileSize=0
EndIf
End Function


EDIT
Most of the code is errror handling. The essential part is this:
Open "YOURFILE.MOD" For input As #10
FileSize=Lof(10)
Close 10


EDIT2
  Quote  My firmware version is 4.01 on the Colour Maximite

I can strongly recommend that you upgrade to 4:05 (MMBasic 4.5). It's easy to do.

Regards
MichaelEdited by twofingers 2015-11-09
causality ≠ correlation ≠ coincidence
 
Yourock17
Newbie

Joined: 09/01/2015
Location: Australia
Posts: 12
Posted: 02:54am 08 Nov 2015
Copy link to clipboard 
Print this post

Thanks for the help, however it errors as "Must be an open COM port". I have no idea what this means. I will update the firmware soon.
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025