dataFile.size(); returning negetive values

I have an issue with the .size() method returing negative vaues. See code exerpt below;

dataFile =;      //the days date
    if (dataFile) {
      archivosize = dataFile.size();      
      Serial.print(F("\nFileSize> "));

The above is part of a larger routine that sends data to an ftp server so teh size of the file is required and, obviously, when the result is negative, the ftp upload fails.

The way it works is that when the program starts it uploads a small test file to the server - this works - then at midnight of each day and each subsequent day it sends teh actual data file - this works for the midnight of the first day (filesize ~20kB) but fails on the midnight of the second day (filesize ~50kB). Could the size of the file be an issue.

Any help is much appreciated.


Check the type of your variable. If it is not unsigned, it may have overflowed and gone negative. Otherwise the function may be trying to return an error. Hope it helps