遍歷整個目錄,這個在錄像搜索時比較有用,我們做設備的在做app錄像查詢,回放,拖拽時都需要用到錄像檢索掃描列表這個功能,我將介紹下簡單的系統函數遍歷目錄的小程序。
#include <dirent.h>
#include <stdio.h>
#include <malloc.h>
int main()
{
struct dirent **namelist;
int n;
n = scandir("/mnt/sdcard/2018-08-03/1", &namelist, 0, alphasort);
if (n < 0)
{
perror("not found\n");
}
else
{
while(n--)
{
printf("%s\n", namelist[n]->d_name);
free(namelist[n]);
}
free(namelist);
}
}