5 Star 12 Fork 3

safedebug / xcguihelper

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
CPath.cpp 1.89 KB
一键复制 编辑 原始数据 按行查看 历史
safedebug 提交于 2016-09-06 15:45 . 增加两个例子
#include "StdAfx.h"
#include "CPath.h"
////////////////////////////////////////////////////////
CEnumPath::~CEnumPath()
{
for (int i = 0; i < m_nCount; i++)
{
if (m_Path[i] != NULL)
{
delete [] m_Path[i];
m_Path[i] = NULL;
}
}
m_nCount = 0;
}
CEnumPath::CEnumPath(const wchar_t* pPath,BOOL bDir,BOOL bFullPath):m_nCount(0)
{
ZeroMemory(m_Path,sizeof(wchar_t*)*MAX_PATH);
WIN32_FIND_DATAW FileData={0};
wchar_t TempPath[MAX_PATH] = {0};
wcscpy(TempPath,pPath);
if (TempPath[wcslen(pPath)] != L'\\')
{
wcscat(TempPath,L"\\");
}
wcscat(TempPath,L"*.*");
HANDLE hSearch = FindFirstFileW(TempPath, &FileData);
if (hSearch == INVALID_HANDLE_VALUE)
{
return;
}
BOOL fFinished = FALSE;
m_nCount = 0;
while (!fFinished)
{
if ((wcscmp(FileData.cFileName,L".") != 0) && (wcscmp(FileData.cFileName,L"..") != 0))
{
if ( (FILE_ATTRIBUTE_DIRECTORY & FileData.dwFileAttributes) != 0 )
{
if (bDir == TRUE)
{
m_Path[m_nCount] = new wchar_t[MAX_PATH_XC];
ZeroMaxPathXC(m_Path[m_nCount]);
if (bFullPath == TRUE)
{
wcscat(m_Path[m_nCount],pPath);
wcscat(m_Path[m_nCount],L"\\");
}
wcscat(m_Path[m_nCount],FileData.cFileName);
m_nCount++;
}
}else
{
if (bDir == FALSE)
{
m_Path[m_nCount] = new wchar_t[MAX_PATH_XC];
ZeroMaxPathXC(m_Path[m_nCount]);
if (bFullPath == TRUE)
{
wcscat(m_Path[m_nCount],pPath);
wcscat(m_Path[m_nCount],L"\\");
}
wcscat(m_Path[m_nCount],FileData.cFileName);
m_nCount++;
}
}
}
ZeroMemory(&FileData,sizeof(FileData));
if (!FindNextFileW(hSearch, &FileData))
{
if (GetLastError() == ERROR_NO_MORE_FILES)
{
fFinished = TRUE;
}
else
{
FindClose(hSearch);
return ;
}
}
}
FindClose(hSearch);
}
wchar_t* CEnumPath::operator[](int n)
{
return m_Path[n];
}
int CEnumPath::GetItemCount()
{
return m_nCount;
}
C++
1
https://gitee.com/safedebug/xcguihelper.git
git@gitee.com:safedebug/xcguihelper.git
safedebug
xcguihelper
xcguihelper
master

搜索帮助