SDcard#

loadfile()#

The loadfile(filename, buffer, len) method loads the named file. If the optional bytearray is None, then an empty file is created.

Parameters

Description

filename

The name of the file to read.

buffer

A pointer to a place in memory where file data will be stored.

len

The length of the buffer in bytes.

Returns: A bytearray with the file data.

is_inserted()#

The is_inserted() method returns the status of the SD Card.

Returns: True if an SD card is inserted into the brain. False if it is not.

size()#

The size(filename) method returns the size in bytes of the named file.

Parameters

Description

filename

The name of the file to check.

Returns: The size of file in bytes.

savefile()#

The savefile(filename, buffer, len) method saves a bytearray into a named file. If the optional bytearray is None, then an empty file is created.

Parameters

Description

filename

The name of the file to write.

buffer

A pointer to a place in memory where file data will be stored.

len

The length of the buffer in bytes.

Returns: The number of bytes written.

// Write the bytearray into a file.
Brain.SDcard.savefile('MyTextFile.txt', bytearray("Hello "))

appendfile()#

The appendfile(filename, buffer, len) method appends a bytearray into a named file. Append is used to add more data to an existing file.

Parameters

Description

filename

The name of the file to write.

buffer

A pointer to a place in memory where file data will be stored.

len

The length of the buffer in bytes.

Returns: The number of bytes written.

# Append the bytearray into a file.
Brain.sdcard.appendfile('MyTextFile.txt', bytearray("World "))

size()#

The size(filename) method returns the size in bytes of the named file.

Parameters

Description

filename

The name of the file to check.

Returns: The size of file in bytes.

exists()#

The exists(filename) method checks to see if the named file exists on the sd card.

Parameters

Description

filename

The name of the file to check.

Returns: true if file exists. false if it does not exist.