NX二次开发—遍历文件夹获取各文件名称并筛选指定格式的文件

#include <iostream>
#include <vector>
#include <io.h>

//封装函数

//遍历文件夹获取各文件名称并筛选指定格式的文件
void  get_need_file(string path, vector<string>& file, string ext)
{
    intptr_t file_handle = 0;
    struct _finddata_t file_info;
    string temp;
    if ((file_handle = _findfirst(temp.assign(path).append("/*" + ext).c_str(), &file_info)) != -1)
    {
        do
        {
            file.push_back(temp.assign(path).append("/").append(file_info.name));
        } while (_findnext(file_handle, &file_info) == 0);
        _findclose(file_handle);
    }
}
 

//函数使用

//string file_path = R"(E:\Test)";//文件夹路径
        vector<string> my_file;
        string need_extension = ".dat";//文件后缀类型
        //获取文件夹里面函数
        get_need_file(file_path , my_file, need_extension);
        UF_UI_open_listing_window();
        for (int i = 0; i < my_file.size(); i++)
        {
            UF_UI_write_listing_window(my_file[i].c_str());//输出
            print("\n");
        }
        if (my_file.size() == 0)
        {
            //cout << "No file can be found!" << endl;

            uc1601("没有模板文件", 1);
        }
        else
        {
                        UF_UI_write_listing_window("dat文件数量");
                 UF_UI_write_listing_window(my_file.size();

        }

  • 4
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值