mjs513
Senior Member+
Added this test for removing directories and files. But did notice that all files have to be removed in the directory for the directory can be removed.
Code:
//next test
//lets make a few files and directories.
Serial.println();
file1 = myfs.open("file1", FILE_WRITE);
file2 = myfs.open("file2", FILE_WRITE);
file3 = myfs.open("file3", FILE_WRITE);
file1.println("this is a test");
file2.println("this is a test");
file3.println("this is a test");
file1.close();
file2.close();
file3.close();
myfs.mkdir("test1");
myfs.mkdir("test2");
myfs.mkdir("test3");
printDirectory();
file1 = myfs.open("/test1/file1", FILE_WRITE);
file2 = myfs.open("/test2/file2", FILE_WRITE);
file3 = myfs.open("/test3/file3", FILE_WRITE);
file1.println("this is a test");
file2.println("this is a test");
file3.println("this is a test");
file1.close();
file2.close();
file3.close();
printDirectory();
//now lets remove them
if(myfs.remove("/test3/file3") == true)
Serial.println("file /test3/file3 removed!");
if(myfs.rmdir("test3") == true)
Serial.println("directory /test3 removed!");
myfs.remove("/test2/file2");
myfs.rmdir("test2");
printDirectory();
Code:
printDirectory
--------------
FILE PRINTOUTPUT1.txt 628
FILE PRINTOUTPUT2.txt 630
FILE file1 16
FILE file2 16
FILE file3 16
DIR structuredData /
FILE logger.txt 480
DIR test1 /
FILE file1 16
DIR test2 /
FILE file2 16
DIR test3 /
FILE file3 16
file /test3/file3 removed!
directory /test3 removed!
printDirectory
--------------
FILE PRINTOUTPUT1.txt 628
FILE PRINTOUTPUT2.txt 630
FILE file1 16
FILE file2 16
FILE file3 16
DIR structuredData /
FILE logger.txt 480
DIR test1 /
FILE file1 16