Windows 下c獲取文件目錄

因爲要插數據庫,構建sql語句,須要文件名,在網上找了半天,無奈都是Linux下的專用函數,傷心,,還有那個下載URL ,還木搞好,就要走啦,心焦哇ios

#include<iostream>
#include<windows.h>
using namespace std;

int main()
{
    WIN32_FIND_DATA  fileAttr;
    HANDLE  handle;
    handle = FindFirstFile("D:\\*", &fileAttr);

    if( handle == INVALID_HANDLE_VALUE ) 
    {
        cout<<"invalid handle value "<<GetLastError()<<endl;
    }
    else
    {
        cout<<fileAttr.cFileName<<endl; //輸出查找到的文件名

        while(  FindNextFile(handle, &fileAttr)  )
        {
            cout<<fileAttr.cFileName<<endl; //輸出每個查找到的文件名
        }

        if( GetLastError() == ERROR_NO_MORE_FILES )
        {
            cout<<"查找完畢"<<endl;
        }
        else 
        {
            cout<<"查找過程出現錯誤"<<endl;
        }

        FindClose(handle);
    }

    return 0;
}
相關文章
相關標籤/搜索