Delete_file prog

Dependencies:   SDFileSystem mbed

Fork of mbed_blinky by Mbed

Files at this revision

API Documentation at this revision

Comitter:
jaspreetsingh
Date:
Tue Feb 17 07:34:36 2015 +0000
Parent:
7:55590c7bed67
Commit message:
Delete the folder from the sd card

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 55590c7bed67 -r 99956653b8c8 main.cpp
--- a/main.cpp	Mon Feb 16 12:28:30 2015 +0000
+++ b/main.cpp	Tue Feb 17 07:34:36 2015 +0000
@@ -1,26 +1,54 @@
 #include "mbed.h"
 #include "SDFileSystem.h"
-
-
-SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "sd");
+ 
+SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "sd"); // MOSI, MISO, SCK, CS
 Serial pc(USBTX, USBRX);
-
+FILE *fp;
+ 
+ 
+uint32_t do_list(const char *fsrc)
+{
+    DIR *d = opendir(fsrc);
+    struct dirent *p;
+    uint32_t counter = 0;
+ 
+    while ((p = readdir(d)) != NULL) {
+        counter++;
+        pc.printf("%s\n", p->d_name);
+        
+    }
+    closedir(d);
+    return counter;
+}
+ 
+void do_remove(const char *fsrc)
+{
+    pc.printf("\r\n Deleting... \r\n");
+    DIR *d = opendir(fsrc);
+    struct dirent *p;
+    char path[100] = {0};
+    while((p = readdir(d)) != NULL) {
+        strcpy(path, fsrc);
+        pc.printf("\r\n path1 is %s\r\n",path);
+        strcat(path, "/");
+        pc.printf("\r\n path2 is %s\r\n",path);
+        strcat(path, p->d_name);
+        pc.printf("\r\n path3 is %s\r\n",path);
+        remove(path);
+    }
+    closedir(d);
+    remove(fsrc);
+}
+ 
 int main()
 {
-    mkdir("/sd/jas",0777);
-    pc.printf("Hello World\r\n");
-    wait(3);
-    pc.printf("Creating test1.txt\r\n");
-    FILE *fp = fopen("/sd/test1.txt","w");
-    fprintf(fp,"Hello World");
-    fclose(fp);
-    pc.printf("File Created\r\n");
-    wait(3);
-    pc.printf("Deleting the File\r\n");
-    wait(3);
+    pc.printf("Initializing \n");
+    wait(2);
     char dest[100]="";
-    sprintf(dest,"/sd/test1.txt");    // Write the name of the file you want to delete from the sd card or empty folder
-    remove(dest);
-    pc.printf("File Deleted\r\n");
         
+    pc.printf("\r\n Deleting Folder \r\n");
+    sprintf(dest,"/sd/NTFT/NTFT1502/NTFT150211/NTFT15021113");      // Enter the name of the folder to be deleted
+    do_remove(dest);
+    pc.printf("\n File Deleted \n");
+   
 }
\ No newline at end of file