操作目录重要函数
操作目录的上下文
- AVIODirEntry
目录项。用于存放文件名,文件大小等信息
#include <libavutil/av_laog.h>
#include <libavformat/avformat.h>
int main()
{
int ret = -1;
AVIODirContext *ctx = NULL;
AVIODirEntry *entry = NULL;
av_log_set_level(AV_LOG_INFO);
ret = avio_open_dir(&ctx, "./", NULL);
if (ret < 0) {
av_log(NULL, AV_LOG_ERROR, "can not open dir:%s\n", av_err2str(ret));
goto END;
}
while (1) {
ret = avio_readdir(ctx, &entry);
if (ret < 0) {
av_log(NULL, AV_LOG_ERROR, "can not readdir :%s\n", av_err2str(ret));
goto END;
}
if (!entry) { //读到目录尾
break;
}
av_log(NULL, AV_LOG_INFO, "%ld %s\n", entry->size, entry->name);
avio_free_directory_entry(&entry);
}
END:
avio_close_dir(ctx);
return 0;
}
编译:
gcc -lavutil -lavformat