You are reading a single comment by @ruvi and its replies. Click here to read the full conversation.
  • I'm working on a project that involves data logging in a CSV, but where there should be the option of editing/deleting the last line of the CSV. I'm not sure how to go about this with a Bangle.

    I was thinking maybe something like loading the whole file into a string, deleting the last line, then re-saving it. But I'm worried about the size of the string being larger than the watch can handle if the file gets very long.

    var file = require("Storage").open("positions.csv",­"r");
    
    // Read whole file with very long length parameter
    csv = file.read(100000);
    
    // Convert to array of lines
    csvNew = csv.split('\n');
    
    // Remove last line
    csvNew.pop();
    
    // Join back into single string
    csvNew = csvNew.join("\n");
    
    var file = require("Storage").open("positions.csv",­ "w");
    
    file.write(csvNew);
    

    Is there a better way to do this?

    Edit: Oh, maybe I can somehow access just the last chunk with the file\5 notation? I don't know if that's a thing.

    It doesn't necessarily have to be in CSV format.

About

Avatar for ruvi @ruvi started