diff options
| author | bernard.xiong <[email protected]> | 2010-02-10 05:03:36 +0000 |
|---|---|---|
| committer | bernard.xiong <[email protected]> | 2010-02-10 05:03:36 +0000 |
| commit | e29be4a90bd05e250362b81ea2695d29043e65e0 (patch) | |
| tree | 7baa1faf8355ce07523350f1db89c4443b025d48 /examples/file/listdir.c | |
| parent | 49e317efc1ca5d1488486c394c518aaba30f3995 (diff) | |
add some file test template.
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@398 bbd45198-f89e-11dd-88c7-29a3b14d5316
Diffstat (limited to 'examples/file/listdir.c')
| -rw-r--r-- | examples/file/listdir.c | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/examples/file/listdir.c b/examples/file/listdir.c new file mode 100644 index 0000000000..86279163e5 --- /dev/null +++ b/examples/file/listdir.c @@ -0,0 +1,55 @@ +/*
+ * File : listdir.c
+ * This file is part of RT-TestCase in RT-Thread RTOS
+ * COPYRIGHT (C) 2010, RT-Thread Development Team
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rt-thread.org/license/LICENSE
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2010-02-10 Bernard first version
+ */
+#include <rtthread.h>
+#include <dfs_posix.h>
+
+void list_dir(const char* path)
+{
+ DIR *dir;
+
+ dir = opendir(path);
+ if (dir != RT_NULL)
+ {
+ struct dfs_dirent* dirent;
+ struct dfs_stat s;
+
+ do
+ {
+ dirent = readdir(dir);
+ if (dirent == RT_NULL) break;
+ rt_memset(&s, 0, sizeof(struct dfs_stat));
+
+ /* build full path for each file */
+ rt_sprintf(fullpath, "/%s", dirent->d_name);
+
+ stat(fullpath, &s);
+ if ( s.st_mode & DFS_S_IFDIR )
+ {
+ rt_kprintf("%s\t\t<DIR>\n", dirent->d_name);
+ }
+ else
+ {
+ rt_kprintf("%s\t\t%lu\n", dirent->d_name, s.st_size);
+ }
+ } while (dirent != RT_NULL);
+
+ closedir(dir);
+ }
+ else rt_kprintf("open %s directory failed\n", path);
+}
+
+#ifdef RT_USING_FINSH
+#include <finsh.h>
+FINSH_FUNCTION_EXPORT(list_dir, list directory);
+#endif
|
