硬汉嵌入式论坛

 找回密码
 立即注册
查看: 4329|回复: 10
收起左侧

[FileX] FileX 如何列出指定目录的文件

[复制链接]

2

主题

1

回帖

7

积分

新手上路

积分
7
发表于 2021-3-11 12:31:07 | 显示全部楼层 |阅读模式
RT, FileX 如何列出指定目录的文件,没找到对应的API
回复

使用道具 举报

38

主题

290

回帖

404

积分

高级会员

积分
404
发表于 2021-3-11 16:34:54 | 显示全部楼层
凑合看吧:

    char fn[MAX_FL_NAME_LEN];
   
    fs_open_dir(TARGET_DIR);

    result = fs_findfirst(fn);

    /* enumerate files */
    for (;;)
    {
        result = fs_findnext(fn);

       if (!result) { break; }
    }
回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106422
QQ
发表于 2021-3-11 16:41:02 | 显示全部楼层
你可以使用fx_directory_first_full_entry_find设置要打开的文件夹

然后此贴浏览:

ThreadX Filex根目录文件浏览功能实现代码,通过函数fx_directory_next_full_entry_find可实现
http://www.armbbs.cn/forum.php?m ... 3364&fromuid=58
(出处: 硬汉嵌入式论坛)
回复

使用道具 举报

38

主题

290

回帖

404

积分

高级会员

积分
404
发表于 2021-3-11 17:12:03 | 显示全部楼层
eric2013 发表于 2021-3-11 16:41
你可以使用fx_directory_first_full_entry_find设置要打开的文件夹

然后此贴浏览:

你这种方法可以支持递归遍历
回复

使用道具 举报

0

主题

2

回帖

2

积分

新手上路

积分
2
发表于 2021-4-10 08:53:42 | 显示全部楼层
  1. CHAR entry_name[FX_MAX_LONG_NAME_LEN];
  2. int ls(char *pathname)
  3. {
  4.     UINT status;
  5.     UINT attributes;
  6.     UINT cnt;
  7.     ULONG size;
  8.     UINT year;
  9.     UINT month;
  10.     UINT day;
  11.     UINT hour;
  12.     UINT minute;
  13.     UINT second;
  14.     char *path;

  15.     if (pathname == FX_NULL)
  16.     {
  17.         path = FX_NULL;
  18.         printf("Directory /:\n");
  19.     }
  20.     else
  21.     {
  22.         path = (char *)pathname;
  23.         printf("Directory %s:\n", path);
  24.     }

  25. // find first
  26.     status = fx_directory_first_full_entry_find(get_nand_flash_disk(0),
  27.              entry_name,
  28.              &attributes,
  29.              &size,
  30.              &year, &month, &day,
  31.              &hour, &minute, &second);
  32.     if (status != FX_SUCCESS)
  33.     {
  34.         return status;
  35.     }
  36.     /* judge file or directory */
  37.     if (attributes & FX_DIRECTORY)
  38.     {
  39.         printf("%-20s", (char *)entry_name);   
  40.         printf("%-25s", "<DIR>");
  41.         printf("%-25lu\n", size);
  42.     }
  43.     else
  44.     {
  45.         printf("%-20s", (char *)entry_name);    /* 长文件名 */
  46.         printf("%-25lu\n", size);
  47.     }


  48.     for (cnt = 0; ; cnt++)
  49.     {
  50.         status = fx_directory_next_full_entry_find(get_nand_flash_disk(0),
  51.                  entry_name,
  52.                  &attributes,
  53.                  &size,
  54.                  &year, &month, &day,
  55.                  &hour, &minute, &second);
  56.         if (status == FX_NO_MORE_ENTRIES)
  57.         {
  58.             return FX_SUCCESS;
  59.         }

  60.         if (status != FX_SUCCESS || entry_name[0] == 0)
  61.         {
  62.             break;
  63.         }

  64.         if (entry_name[0] == '.')
  65.         {
  66.             continue;
  67.         }

  68.         /* judge file or directory */
  69.         if (attributes & FX_DIRECTORY)
  70.         {
  71.             printf("%-20s", (char *)entry_name);    /* 长文件名 */
  72.             printf("%-25s\n", "<DIR>");
  73.         }
  74.         else
  75.         {
  76.             printf("%-20s", (char *)entry_name);    /* 长文件名 */
  77.             printf("%-25lu\n", size);
  78.         }

  79.     }

  80.     return status;
  81. }
复制代码
回复

使用道具 举报

0

主题

2

回帖

2

积分

新手上路

积分
2
发表于 2021-4-10 08:54:23 | 显示全部楼层
  1. CHAR entry_name[FX_MAX_LONG_NAME_LEN];
  2. int ls(char *pathname)
  3. {
  4.     UINT status;
  5.     UINT attributes;
  6.     UINT cnt;
  7.     ULONG size;
  8.     UINT year;
  9.     UINT month;
  10.     UINT day;
  11.     UINT hour;
  12.     UINT minute;
  13.     UINT second;
  14.     char *path;

  15.     if (pathname == FX_NULL)
  16.     {
  17.         path = FX_NULL;
  18.         printf("Directory /:\n");
  19.     }
  20.     else
  21.     {
  22.         path = (char *)pathname;
  23.         printf("Directory %s:\n", path);
  24.     }

  25. // find first
  26.     status = fx_directory_first_full_entry_find(get_nand_flash_disk(0),
  27.              entry_name,
  28.              &attributes,
  29.              &size,
  30.              &year, &month, &day,
  31.              &hour, &minute, &second);
  32.     if (status != FX_SUCCESS)
  33.     {
  34.         return status;
  35.     }
  36.     /* judge file or directory */
  37.     if (attributes & FX_DIRECTORY)
  38.     {
  39.         printf("%-20s", (char *)entry_name);   
  40.         printf("%-25s", "<DIR>");
  41.         printf("%-25lu\n", size);
  42.     }
  43.     else
  44.     {
  45.         printf("%-20s", (char *)entry_name);    /* 长文件名 */
  46.         printf("%-25lu\n", size);
  47.     }


  48.     for (cnt = 0; ; cnt++)
  49.     {
  50.         status = fx_directory_next_full_entry_find(get_nand_flash_disk(0),
  51.                  entry_name,
  52.                  &attributes,
  53.                  &size,
  54.                  &year, &month, &day,
  55.                  &hour, &minute, &second);
  56.         if (status == FX_NO_MORE_ENTRIES)
  57.         {
  58.             return FX_SUCCESS;
  59.         }

  60.         if (status != FX_SUCCESS || entry_name[0] == 0)
  61.         {
  62.             break;
  63.         }

  64.         if (entry_name[0] == '.')
  65.         {
  66.             continue;
  67.         }

  68.         /* judge file or directory */
  69.         if (attributes & FX_DIRECTORY)
  70.         {
  71.             printf("%-20s", (char *)entry_name);    /* 长文件名 */
  72.             printf("%-25s\n", "<DIR>");
  73.         }
  74.         else
  75.         {
  76.             printf("%-20s", (char *)entry_name);    /* 长文件名 */
  77.             printf("%-25lu\n", size);
  78.         }

  79.     }

  80.     return status;
  81. }
复制代码
回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106422
QQ
发表于 2021-4-11 10:16:57 | 显示全部楼层
回复

使用道具 举报

1

主题

16

回帖

19

积分

新手上路

积分
19
发表于 2021-11-22 20:03:13 | 显示全部楼层

fx_directory_first_full_entry_find并不能改变扫描的目录吧?需要通过改变默认目录,再执行扫描才行。而且只用fx_directory_next_full_entry_find就可以了其实。
回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106422
QQ
发表于 2022-8-30 16:34:05 | 显示全部楼层
下面函数可以设置子目录搜索。

image.png
回复

使用道具 举报

0

主题

1

回帖

1

积分

新手上路

积分
1
发表于 2024-4-10 13:16:47 | 显示全部楼层
fx_directory_first_full_entry_find   是查找目录里面的第一条,如果目里面都是文件,那第一条是日期最老的文件么? 我该如何按照日期遍历文件呢?
回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106422
QQ
发表于 2024-4-11 11:04:25 | 显示全部楼层
leozhangsd 发表于 2024-4-10 13:16
fx_directory_first_full_entry_find   是查找目录里面的第一条,如果目里面都是文件,那第一条是日期最老 ...

遍历的顺序估计是按照FAT表里面文件存储顺序检索的。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|Archiver|手机版|硬汉嵌入式论坛

GMT+8, 2024-4-19 18:04 , Processed in 0.250725 second(s), 28 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表