_chdir、_findfirst、_findnext、_findclose函數的使用(枚舉文件)

#include <stdio.h>
#include <direct.h>
#include <io.h>

void demo()
{
    intptr_t handle = NULL;
    intptr_t handle_next = NULL;
    struct _finddata_t cfile = {0};

    _chdir("D:\\test\\"); // 改變當前目錄;即:進入指定目錄
    handle = _findfirst("*.mp3", &cfile); // 在當前目錄下查找文件或子目錄;[支持通配符]
    handle_next = handle;
    while (handle_next != -1)
    {
        printf("[%s],[%dbyte]\n", cfile.name, cfile.size);

        handle_next = _findnext(handle, &cfile); // 繼續查找下一個
    }
    _findclose(handle);
}

int main(void)
{
    demo();

    getchar();
    return 0;
}

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