天气与日历 切换到窄版

 找回密码
 立即注册
中国膜结构网
十大进口膜材评选 十大国产膜材评选 十大膜结构设计评选 十大膜结构公司评选
查看: 51|回复: 0

C++ 获取当前目录下的指定后缀文件

[复制链接]
  • TA的每日心情
    开心
    昨天 15:13
  • 签到天数: 153 天

    [LV.7]常住居民III

    3456

    主题

    553

    回帖

    214748万

    积分

    管理员

    中国膜结构网www.mjgou.com

    积分
    2147483647
    QQ
    发表于 2024-7-26 08:25:24 | 显示全部楼层 |阅读模式
    #include "shlwapi.h"
    #pragma comment(lib,"shlwapi.lib")
    #pragma comment(lib, "Version.lib ")
    #include <iostream>
    #include <windows.h>
    #include <algorithm>
    #include <time.h>
    #include <io.h>
    #include <fstream>

    struct tagFileInfo
    {
            ULONG uLen;
            int nCreateTime;
            int nModifyTime;
            string strFileName;
    };

    // // 获取指定目录下的所有指定格式文件,返回的列表将按照创建时间排序,最早的在最前面
    bool getDirFiles(string strDir, vector<tagFileInfo>& vecFiles,string strSuffixName)
    {
            if (strDir.empty() || !isExistFile(strDir, true))
            {
                    return false;
            }

            vecFiles.clear();
            string strPath = strDir + "*.*" + strSuffixName;

            // 文件信息
            struct _finddata_t _fileInfo;
           
            // 文件句柄
            intptr_t hFile = _findfirst(strPath.c_str(), &_fileInfo);
            if (-1 != hFile)
            {
                    do
                    {
                            string strFileName = strDir + string(_fileInfo.name);
                            if (isExistFile(strFileName))
                            {
                                    tagFileInfo _tagInfo;
                                    _tagInfo.nCreateTime = static_cast<int>(_fileInfo.time_create);
                                    _tagInfo.nModifyTime = static_cast<int>(_fileInfo.time_write);
                                    _tagInfo.uLen = static_cast<int>(_fileInfo.size);
                                    _tagInfo.strFileName = strFileName;
                                    vecFiles.push_back(_tagInfo);
                            }
                    } while (0 == _findnext(hFile, &_fileInfo));
            }
            return true;
    }






    #include <vector>

    using namespace std;

    string m_strDir = "XXX/XX/XX";//目标目录

    vector<tagFileInfo> vecFiles;
    getDirFiles(m_strDir, vecFiles, "log");





     

     

     

     

    C++ 获取当前目录下的指定后缀文件
    中国膜结构网打造全中国最好的膜结构综合平台 ,统一协调膜结构设计,膜结构施工,膜材采购,膜材定制,膜结构预算全方位服务。 中国空间膜结构协会合作单位。
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    QQ|Archiver|手机版|中国膜结构网|中国膜结构协会|进口膜材|国产膜材|ETFE|PVDF|PTFE|设计|施工|安装|车棚|看台|污水池| |网站地图

    GMT+8, 2024-9-8 09:25 , Processed in 0.066546 second(s), 22 queries .

    Powered by Discuz! X3.5

    © 2001-2024 Discuz! Team.

    快速回复 返回顶部 返回列表