|
-
- #include <SPI.h>
- #include "SdFat.h"
-
-
- const uint8_t chipSelect = SS;
-
-
- SdFat sd;
-
-
- ArduinoOutStream cout(Serial);
-
-
- #define error(s) sd.errorHalt(F(s))
-
- void setup() {
- Serial.begin(9600);
-
-
- while (!Serial) {
- SysCall::yield();
- }
- cout << F("Insert an empty SD. Type any character to start.") << endl;
- while (Serial.read() <= 0) {
- SysCall::yield();
- }
-
-
-
- if (!sd.begin(chipSelect, SPI_HALF_SPEED)) {
- sd.initErrorHalt();
- }
-
-
- if (sd.exists("dir2/DIR3/NAME3.txt")) {
- cout << F("Removing /dir2/DIR3/NAME3.txt") << endl;
- if (!sd.remove("dir2/DIR3/NAME3.txt") ||
- !sd.rmdir("dir2/DIR3/") ||
- !sd.rmdir("dir2/")) {
- error("remove/rmdir failed");
- }
- }
-
- SdFile file("Name1.txt", O_WRITE | O_CREAT);
- if (!file.isOpen()) {
- error("Name1.txt");
- }
- file.println("A test line for Name1.txt");
-
-
-
- if (!file.rename(sd.vwd(), "name2.txt")) {
- error("name2.txt");
- }
- file.println("A test line for name2.txt");
-
-
- cout << F("------") << endl;
- sd.ls(LS_R);
-
-
- if (!sd.mkdir("Dir1")) {
- error("Dir1");
- }
-
-
- if (!file.rename(sd.vwd(), "Dir1/NAME3.txt")) {
- error("NAME3.txt");
- }
- file.println("A line for Dir1/NAME3.txt");
-
-
- cout << F("------") << endl;
- sd.ls(LS_R);
-
-
- if (!sd.mkdir("dir2")) {
- error("dir2");
- }
-
-
- file.close();
-
-
- if (!sd.rename("Dir1", "dir2/DIR3")) {
- error("dir2/DIR3");
- }
-
-
- if (!file.open("dir2/DIR3/NAME3.txt", O_WRITE | O_APPEND)) {
- error("dir2/DIR3/NAME3.txt");
- }
- file.println("A line for dir2/DIR3/NAME3.txt");
- file.close();
-
-
- cout << F("------") << endl;
- sd.ls(LS_R);
-
- cout << F("Done") << endl;
- }
- void loop() {}
|