I'm using this block of code to read and sum up the bytes of all the text files I have on an SD card:
long get_sd_memory_taken() { File dir = SD.open("/"); long sd_memory_taken; int c = 0; while (true) { File entry = dir.openNextFile(); if (!entry) { return sd_memory_taken; break; } if(strcmp(entry.name(), "SYSTEM~1") == 0) { continue; } if(c > 15) { tft.println(entry.name()); tft.println(entry.size()); } sd_memory_taken += entry.size(); entry.close(); c++; } } The SD card is 8GB so the number won't be larger than 8,589,934,592. The function get_sd_memory_taken() returns the number so it can be send to a phone using Bluetooth. I just checked that long can hold max 2,147,483,647, so if the SD card is filled more than that, I suppose errors are gonna appear. How can I prevent this? I was thinking of maybe using a double and put the comma maybe 5 digits to the left and send that or maybe divide the number into 10 smaller longs and send them to the phone separately. I think the former method is better but I'm not sure if it'll work. What's the best way to go about this problem where I'm trying to use as less memory as possible?
unsigned long longakauint64_tcan hold up to 9,223,372,036,854,775,807.