2010-02-10 13:03:36 +08:00
|
|
|
/*
|
|
|
|
* 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>
|
|
|
|
|
2010-02-11 23:59:25 +08:00
|
|
|
static char fullpath[256];
|
2010-02-10 13:03:36 +08:00
|
|
|
void list_dir(const char* path)
|
|
|
|
{
|
|
|
|
DIR *dir;
|
|
|
|
|
|
|
|
dir = opendir(path);
|
|
|
|
if (dir != RT_NULL)
|
|
|
|
{
|
2011-07-04 07:16:59 +08:00
|
|
|
struct dirent* dirent;
|
|
|
|
struct stat s;
|
2010-02-10 13:03:36 +08:00
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
dirent = readdir(dir);
|
|
|
|
if (dirent == RT_NULL) break;
|
2011-07-04 07:16:59 +08:00
|
|
|
rt_memset(&s, 0, sizeof(struct stat));
|
2010-02-10 13:03:36 +08:00
|
|
|
|
|
|
|
/* build full path for each file */
|
2012-07-03 07:28:06 +08:00
|
|
|
rt_sprintf(fullpath, "%s/%s", path, dirent->d_name);
|
2010-02-10 13:03:36 +08:00
|
|
|
|
|
|
|
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
|