File handling examples

Can anyone point me at some good file handling examples for the SD card on the Yun? I don't have a lot of linux experience so I'm struggling to know what sort of paths I should be using.

Many thanks


My experience is also limited, so I just follow some tutorials.
For example this Python script will write a file to the SD card:


# Open a file
fo = open("/mnt/sd/test.txt", "wb")
fo.write( "Line 1\n");
fo.write( "Line 2\n");
fo.write( "Line 3\n");
fo.write( "Line 4\n");

# Close opend file

If you need to do simple things, consider taking a look at the datalogger example (one of the Bridge examples)

A rule of thumb is to have a SD card with an "arduino" folder plugged in, so that the Yun makes folder /mnt/sd available, and use yun flash as least as possible

Thanks. That's really useful. I'll give it a try.


for Read

  File dataFile ="/mnt/sd/Arduino/www/sample/file.txt");
  while (dataFile.available()) {
        text=text + (char);

for write

File dataFile ="/mnt/sd/Arduino/www/Sample/file.txt", FILE_WRITE);
                 ;          //only to write from the beginning of file

if you have to pass a string as the file path use this code

 String path="/mnt/sd/Arduino/www/Sample/" + STRING +".txt";
  File dataFiles =;

All your advice really helped. I've got the programme working now.

Many thanks


2 years later and still helpful!

Thank you, I needed:

String path="/mnt/sd/Arduino/www/Sample/" + STRING +".txt";
File dataFiles =;

And you beat me to it!