123

Dependencies:   mbed

Committer:
lozeonjyu
Date:
Tue Oct 01 22:28:19 2019 +0000
Revision:
0:3c8241f877e9
123

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lozeonjyu 0:3c8241f877e9 1 #include "mbed.h"
lozeonjyu 0:3c8241f877e9 2
lozeonjyu 0:3c8241f877e9 3 LocalFileSystem local("local"); // Create the local filesystem under the name "local"
lozeonjyu 0:3c8241f877e9 4
lozeonjyu 0:3c8241f877e9 5 int main() {
lozeonjyu 0:3c8241f877e9 6 FILE *fp = fopen("/local/out.txt", "w"); // Open "out.txt" on the local file system for writing
lozeonjyu 0:3c8241f877e9 7 fprintf(fp, "Hello World!");
lozeonjyu 0:3c8241f877e9 8 fclose(fp);
lozeonjyu 0:3c8241f877e9 9 remove("/local/out.txt"); // Removes the file "out.txt" from the local file system
lozeonjyu 0:3c8241f877e9 10
lozeonjyu 0:3c8241f877e9 11 DIR *d = opendir("/local"); // Opens the root directory of the local file system
lozeonjyu 0:3c8241f877e9 12 struct dirent *p;
lozeonjyu 0:3c8241f877e9 13 while((p = readdir(d)) != NULL) { // Print the names of the files in the local file system
lozeonjyu 0:3c8241f877e9 14 printf("%s\n", p->d_name); // to stdout.
lozeonjyu 0:3c8241f877e9 15 }
lozeonjyu 0:3c8241f877e9 16 closedir(d);
lozeonjyu 0:3c8241f877e9 17 }