Windows 下c获取文件目录

#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;
}



你可能感兴趣的:(Windows 下c获取文件目录)