vio_open_dir
avio_read_dir
Code
#include
void dir_function(void)
{
AVIOContext * ctx = NULL; // 目录操作上下文
AVIODirEntry * entry = NULL; // 目录项
av_log_set_level(AV_LOG_DEBUG); // 设置日志等级
int ret = avio_open_dir(&ctx, "./A", NULL);
if (ret < 0)
{
av_log(NULL, AV_LOG_ERROR, "cant open dir %s\n", av_err2str(ret));
goto __fail;
}
#if 0
ret = avio_read_dir(ctx, &entry);
av_log(NULL, AV_LOG_INFO,
"File Name:%s, File Size:%ld\n", entry->name, entry->size);
avio_free_directory_entry(&entry);
avio_free_directory_entry(&entry);
goto __fail;
#endif
while (1)
{
ret = avio_read_dir(ctx, &entry);
if (ret < 0)
{
av_log(NULL, AV_LOG_ERROR, "Cant read dir\n");
goto __fail;
}
// 如果entry是NULL,则代表目录到末尾退出
if (!entry)
break;
av_log(NULL, AV_LOG_INFO,
"File Name:%s, File Size:%ld\n", entry->name, entry->size);
avio_free_directory_entry(&entry);
}
__fail:
avio_close(&ctx);
}