您的位置:首页 > 健康 > 美食 > 网站设计的研究方案_想学服装设计去哪个大学好_营销网站建设教学_百度人工

网站设计的研究方案_想学服装设计去哪个大学好_营销网站建设教学_百度人工

2025/1/6 16:36:09 来源:https://blog.csdn.net/weixin_60669486/article/details/144880018  浏览:    关键词:网站设计的研究方案_想学服装设计去哪个大学好_营销网站建设教学_百度人工
网站设计的研究方案_想学服装设计去哪个大学好_营销网站建设教学_百度人工

ComDir.h


/*
@author:EricsT
@data:20241031
@version:V1.0
@history:@author @data @version @contentEricsT 20241031 V1.0 新增ComDir类[判断存在性以及创建目录]EricsT 20241101 V1.1 修改isDirExists函数,新增getFilesFromDir函数
*/#pragma once#include <string>
#include <fstream>
#include <vector>
using namespace std;class ComDir
{
public:/*func:判断文件夹是否存在@strDirPath:文件夹路径@csDirPath:文件夹路径@pchDirPath:文件夹路径ret:存在true,不存在false*/static bool isDirExists(string strDirPath);static bool isDirExists(CString csDirPath);static bool isDirExists(PCHAR pchDirPath);/*func:创建文件夹@strDirPath:文件夹路径@csDirPath:文件夹路径@pchDirPath:文件夹路径ret:创建成功true,创建失败false*/static bool creatDir(string strDirPath);static bool creatDir(CString csDirPath);static bool creatDir(PCHAR pchDirPath);/*func:获取文件夹[包括子文件夹]内的文件@strDirPath/csDirPath/pchDirPath:文件夹路径@strExtension/csExtension/pchExtension:扩展名ret:vector<string>文件容器*/static vector<string> getFilesFromDir(string strDirPath, string strExtension = "*");static vector<string> getFilesFromDir(CString csDirPath, CString csExtension = CString("*"));static vector<string> getFilesFromDir(PCHAR pchDirPath, PCHAR pchExtension = "*");};

ComDir.cpp


/*
@author:EricsT
@data:20241031
@version:V1.1
*/#include "stdafx.h"
#include "ComDir.h"
#include <io.h>
#include <direct.h>bool ComDir::isDirExists(string strDirPath)
{struct _finddata_t fileInfo;if (-1 == _findfirst(strDirPath.c_str(), &fileInfo))//取文件信息,不存在则为-1return false;if (fileInfo.attrib & _A_SUBDIR)return true;return false;
}bool ComDir::isDirExists(CString csDirPath)
{//CStringToStringint len = csDirPath.GetLength();PCHAR pch = new char[len + 1];size_t pchSize = wcstombs(pch, csDirPath, len + 1);if (pchSize == wstring::npos){delete pch;return "";}string strDirPath(pch);delete pch;struct _finddata_t fileInfo;if (-1 == _findfirst(strDirPath.c_str(), &fileInfo))return false;if (fileInfo.attrib & _A_SUBDIR)return true;return false;}bool ComDir::isDirExists(PCHAR pchDirPath){struct _finddata_t fileInfo;if (-1 == _findfirst(pchDirPath, &fileInfo))//取文件信息,不存在则为-1return false;if (fileInfo.attrib & _A_SUBDIR)return true;return false;}bool ComDir::creatDir(string strDirPath)
{string strCreate = strDirPath;string strCoplete = strDirPath.substr(0, 2);//取系统盘strCreate = strCreate.substr(3);//除去系统盘之后的路径while (true){size_t iPos = strCreate.find('\\');strCoplete += '\\' + strCreate.substr(0, iPos);//按层级取目录if (-1 == _access(strCoplete.c_str(), 0)) //判断该目录是否存在{if (0 != _mkdir(strCoplete.c_str()))//不存在就创建目录return false;}if (strCreate.npos == iPos)//最后一级目录break;strCreate = strCreate.substr(iPos + 1);}return true;
}bool ComDir::creatDir(CString csDirPath)
{//CStringToStringint len = csDirPath.GetLength();PCHAR pch = new char[len + 1];size_t pchSize = wcstombs(pch, csDirPath, len + 1);if (pchSize == wstring::npos){delete pch;return "";}string strDirPath(pch);delete pch;string strCreate = strDirPath;string strCoplete = strDirPath.substr(0, 2);strCreate = strCreate.substr(3);while (true){size_t iPos = strCreate.find('\\');strCoplete += '\\' + strCreate.substr(0, iPos);if (-1 == _access(strCoplete.c_str(), 0)){if (0 != _mkdir(strCoplete.c_str()))return false;}if (strCreate.npos == iPos)break;strCreate = strCreate.substr(iPos + 1);}return true;
}bool ComDir::creatDir(PCHAR pchDirPath)
{string strDirPath(pchDirPath);string strCreate = strDirPath;string strCoplete = strDirPath.substr(0, 2);strCreate = strCreate.substr(3);while (true){size_t iPos = strCreate.find('\\');strCoplete += '\\' + strCreate.substr(0, iPos);if (-1 == _access(strCoplete.c_str(), 0)){if (0 != _mkdir(strCoplete.c_str()))return false;}if (strCreate.npos == iPos)break;strCreate = strCreate.substr(iPos + 1);}return true;
}std::vector<std::string> ComDir::getFilesFromDir(string strDirPath, string strExtension /*= "*"*/)
{vector<string> strRetVec;struct _finddata_t fileInfo;long hFile = 0;if (-1 == (hFile = _findfirst((strDirPath + "\\*.*").c_str(), &fileInfo)))//判断路径是否存在return strRetVec;do{if (fileInfo.attrib & _A_SUBDIR)//判断是否是目录{if (("." == string(fileInfo.name)) || (".." == string(fileInfo.name)))continue;vector<string> vec = getFilesFromDir(strDirPath + "\\" + fileInfo.name, strExtension);//递归获取子目录文件strRetVec.insert(strRetVec.end(), vec.begin(), vec.end());//将子容器合并到母容器内continue;}if ("*" == strExtension)//无指定扩展名{strRetVec.push_back(fileInfo.name);continue;}string strName = fileInfo.name;size_t iPos = strName.find_last_of('.');if (strName.npos == iPos){if ("" == strExtension)strRetVec.push_back(fileInfo.name);//目标文件continue;}if (strExtension != strName.substr(iPos + 1))//和指定扩展名不一致continue;strRetVec.push_back(fileInfo.name);//目标文件} while (0 == _findnext(hFile, &fileInfo));return strRetVec;
}std::vector<std::string> ComDir::getFilesFromDir(CString csDirPath, CString csExtension /*= CString("*")*/)
{vector<string> strRetVec;//CStringToStringint len = csDirPath.GetLength();PCHAR pch = new char[len + 1];size_t pchSize = wcstombs(pch, csDirPath, len + 1);if (pchSize == wstring::npos){delete pch;return strRetVec;}string strDirPath(pch);delete pch;//CStringToStringint len_1 = csExtension.GetLength();PCHAR pch_1 = new char[len_1 + 1];size_t pchSize_1 = wcstombs(pch_1, csExtension, len_1 + 1);if (pchSize_1 == wstring::npos){delete pch_1;return strRetVec;}string strExtension(pch_1);delete pch_1;struct _finddata_t fileInfo;long hFile = 0;if (-1 == (hFile = _findfirst((strDirPath + "\\*.*").c_str(), &fileInfo)))return strRetVec;do{if (fileInfo.attrib & _A_SUBDIR){if (("." == string(fileInfo.name)) || (".." == string(fileInfo.name)))continue;CString csPath = csDirPath + CString("\\") + CString(fileInfo.name);vector<string> vec = getFilesFromDir(csPath, csExtension);strRetVec.insert(strRetVec.end(), vec.begin(), vec.end());continue;}if ("*" == strExtension){strRetVec.push_back(fileInfo.name);continue;}string strName = fileInfo.name;size_t iPos = strName.find_last_of('.');if (strName.npos == iPos){if ("" == strExtension)strRetVec.push_back(fileInfo.name);continue;}if (strExtension != strName.substr(iPos + 1))continue;strRetVec.push_back(fileInfo.name);} while (0 == _findnext(hFile, &fileInfo));return strRetVec;
}std::vector<std::string> ComDir::getFilesFromDir(PCHAR pchDirPath, PCHAR pchExtension /*= "*"*/)
{vector<string> strRetVec;struct _finddata_t fileInfo;long hFile = 0;if (-1 == (hFile = _findfirst((string(pchDirPath) + "\\*.*").c_str(), &fileInfo)))return strRetVec;do{if (fileInfo.attrib & _A_SUBDIR){if (("." == string(fileInfo.name)) || (".." == string(fileInfo.name)))continue;string strPath = string(pchDirPath) + "\\" + string(fileInfo.name);vector<string> vec = getFilesFromDir(strPath.c_str(), pchExtension);strRetVec.insert(strRetVec.end(), vec.begin(), vec.end());continue;}if ("*" == string(pchExtension)){strRetVec.push_back(fileInfo.name);continue;}string strName = fileInfo.name;size_t iPos = strName.find_last_of('.');if (strName.npos == iPos){if ("" == string(pchExtension))strRetVec.push_back(fileInfo.name);continue;}if (string(pchExtension) != strName.substr(iPos + 1))continue;strRetVec.push_back(fileInfo.name);} while (0 == _findnext(hFile, &fileInfo));return strRetVec;
}

关注灵活就业新业态,关注公账号:贤才宝(贤才宝https://www.51xcbw.com) 

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com