Windows 下c获取文件目录

由于要插数据库,构建sql语句,需要文件名,在网上找了半天,无奈都是Linux下的专用函数,伤心,,还有那个下载URL ,还木搞好,就要走啦,心焦哇

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


 

原文地址:https://www.cnblogs.com/zibuyu/p/3278552.html