使用系統函數scandir遍歷目錄的小程序

遍歷整個目錄,這個在錄像搜索時比較有用,我們做設備的在做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);
        }
     } 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章