|
| 1 | +#include <Arduino_UnifiedStorage.h> |
| 2 | + |
| 3 | +InternalStorage internalStorage = InternalStorage(2, "user", FS_LITTLEFS); |
| 4 | + |
| 5 | + |
| 6 | +void setup() { |
| 7 | + /* UNCOMMENT THIS PART IF YOU WANT TO ENABLE FORMATTING*/ |
| 8 | + |
| 9 | + |
| 10 | + |
| 11 | + Serial.begin(9600); |
| 12 | + delay(1000); // Give time to open the Serial Monitor |
| 13 | + while(!Serial); |
| 14 | + |
| 15 | + |
| 16 | + |
| 17 | + internalStorage.formatLittleFS(); |
| 18 | + internalStorage.begin(); |
| 19 | + |
| 20 | + |
| 21 | + Folder root = internalStorage.getRootFolder(); |
| 22 | + Serial.println(root.getPathString()); |
| 23 | + |
| 24 | + // Test copyTo |
| 25 | + Serial.println("Testing copyTo..."); |
| 26 | + Folder sourceFolder2 = root.createSubfolder("source_folder"); |
| 27 | + Serial.println("Folder 1 created"); |
| 28 | + |
| 29 | + Serial.println("Trying to create a folder on top of an existing one... without overwrite"); |
| 30 | + Folder sourceFolder3 = root.createSubfolder("source_folder"); |
| 31 | + |
| 32 | + Serial.println("Trying to create a folder on top of an existing one... with overwrite"); |
| 33 | + Folder sourceFolder4 = root.createSubfolder("source_folder", true); |
| 34 | + |
| 35 | + Folder destinationFolder2 = root.createSubfolder("destination_folder"); |
| 36 | + Serial.println("Folder 2 created"); |
| 37 | + |
| 38 | + Serial.println(sourceFolder2.getPathString()); |
| 39 | + Serial.println(destinationFolder2.getPathString()); |
| 40 | + |
| 41 | + Serial.println(); |
| 42 | + Serial.println(); |
| 43 | + |
| 44 | + |
| 45 | + bool copyResult = sourceFolder2.copyTo(destinationFolder2, true); // Overwrite if exists |
| 46 | + if (copyResult) { |
| 47 | + Serial.println("Copy successful"); |
| 48 | + } else { |
| 49 | + Serial.println("Copy failed"); |
| 50 | + } |
| 51 | + Serial.println(); |
| 52 | + |
| 53 | + |
| 54 | + |
| 55 | + |
| 56 | + // Test moveTo |
| 57 | + Folder sourceFolder = root.createSubfolder("source"); |
| 58 | + Folder destinationFolder = root.createSubfolder("destination"); |
| 59 | + |
| 60 | + |
| 61 | + Serial.println(); |
| 62 | + Serial.println(); |
| 63 | + Serial.println("Testing moveTo..."); |
| 64 | + bool moveResult = sourceFolder.moveTo(destinationFolder, true); // Overwrite if exists |
| 65 | + if (moveResult) { |
| 66 | + Serial.println("Move successful"); |
| 67 | + } else { |
| 68 | + Serial.println("Move failed"); |
| 69 | + } |
| 70 | + |
| 71 | + |
| 72 | + Folder someFolder = root.createSubfolder("lets_put_files_here"); |
| 73 | + UFile someFile = someFolder.createFile("somefile.txt", FileMode::WRITE); |
| 74 | + |
| 75 | + |
| 76 | + |
| 77 | + Folder someOtherFolder = root.createSubfolder("lets_put_files_here"); |
| 78 | + UFile someOtherFile = someFolder.createFile("somefile.txt", FileMode::WRITE); |
| 79 | + |
| 80 | + |
| 81 | + bool success = someFile.copyTo(someOtherFolder); |
| 82 | + Serial.println("trying to copy file without overwrite"); |
| 83 | + Serial.println(success); |
| 84 | + |
| 85 | + success = someFile.copyTo(someOtherFolder,true); |
| 86 | + Serial.println("trying to copy file with overwrite"); |
| 87 | + Serial.println(success); |
| 88 | + |
| 89 | + |
| 90 | + |
| 91 | +} |
| 92 | + |
| 93 | +void loop() { |
| 94 | + // Nothing to do here |
| 95 | +} |
0 commit comments