VC中我有多个txt存在同一个文件夹下,我想通过CFileDialog类选择文件夹进行批处理,而不是
VC中我有多个txt存在同一个文件夹下,我想通过CFileDialog类选择文件夹进行批处理,而不是一一选择每个txt进行处理,怎么办啊?...
VC中我有多个txt存在同一个文件夹下,我想通过CFileDialog类选择文件夹进行批处理,而不是一一选择每个txt进行处理,怎么办啊?
展开
2013-08-12
展开全部
////////////////////////////////////////////////////////////////////////获取文件夹下所有文件
//自己添加这两行,与多文件操作,判断文件(夹)是否存在有关
#pragma
comment(lib,
"shlwapi.lib")
#include "shlwapi.h"
{
CString strFolderDirection="";
GetDirection(strFolderDirection);
GetMultiFilePahtName(strFolderDirection,ArrayE00Path,"*.txt");
}
void CAutoClickDlg::GetDirection(CString &FolderDir)
{LPMALLOC<br>pMalloc;<br> /*Gets the Shell's default allocator */<br> if<br>(::SHGetMalloc(&pMalloc)<br>==<br>NOERROR)<br> {<br> <br>BROWSEINFO<br>bi;<br> <br>char<br>pszBuffer[MAX_PATH];<br> <br>for (int i=0;i<MAX_PATH;i++) pszBuffer[i]=' ';//将pszBuffer全部赋为空格<br> LPITEMIDLIST<br>pidl;<br> <br>//Get help on BROWSEINFO struct-it's got all the bit settings.<br> <br>bi.hwndOwner<br>= GetSafeHwnd();<br> <br>bi.pidlRoot<br>= NULL;<br> <br>bi.pszDisplayName<br>= pszBuffer;<br> <br>bi.lpszTitle<br>= _T("请选择文件目录:");<br> <br>bi.ulFlags<br>= BIF_RETURNFSANCESTORS<br>| BIF_RETURNONLYFSDIRS;<br> <br>bi.lpfn<br>= NULL;<br> <br>bi.lParam<br>= 0;<br> <br>if<br>((pidl<br>= ::SHBrowseForFolder(&bi))<br>!=<br>NULL)<br> <br>{ <br> <br>::SHGetPathFromIDList(pidl, pszBuffer);<br> pMalloc->Free(pidl);<br> <br>}
pMalloc->Release();
FolderDir=pszBuffer;
}
}
void CAutoClickDlg::GetMultiFilePahtName(CString folder, CStringArray &files, CString filter)
{
CFileFind FFind;
CString
szDir
= folder;
if(szDir.Right(1)
!=
"\\\\")szDir
+=
"\\\\";
szDir
+=
filter;
BOOL Ressult
= FFind.FindFile(szDir);
CString Filepath;
while(Ressult)
{
Ressult = FFind.FindNextFile();
if(!FFind.IsDirectory()&&!FFind.IsDots())
{
Filepath=FFind.GetFilePath();
files.Add(Filepath);
}
}
FFind.Close();
}
//自己添加这两行,与多文件操作,判断文件(夹)是否存在有关
#pragma
comment(lib,
"shlwapi.lib")
#include "shlwapi.h"
{
CString strFolderDirection="";
GetDirection(strFolderDirection);
GetMultiFilePahtName(strFolderDirection,ArrayE00Path,"*.txt");
}
void CAutoClickDlg::GetDirection(CString &FolderDir)
{LPMALLOC<br>pMalloc;<br> /*Gets the Shell's default allocator */<br> if<br>(::SHGetMalloc(&pMalloc)<br>==<br>NOERROR)<br> {<br> <br>BROWSEINFO<br>bi;<br> <br>char<br>pszBuffer[MAX_PATH];<br> <br>for (int i=0;i<MAX_PATH;i++) pszBuffer[i]=' ';//将pszBuffer全部赋为空格<br> LPITEMIDLIST<br>pidl;<br> <br>//Get help on BROWSEINFO struct-it's got all the bit settings.<br> <br>bi.hwndOwner<br>= GetSafeHwnd();<br> <br>bi.pidlRoot<br>= NULL;<br> <br>bi.pszDisplayName<br>= pszBuffer;<br> <br>bi.lpszTitle<br>= _T("请选择文件目录:");<br> <br>bi.ulFlags<br>= BIF_RETURNFSANCESTORS<br>| BIF_RETURNONLYFSDIRS;<br> <br>bi.lpfn<br>= NULL;<br> <br>bi.lParam<br>= 0;<br> <br>if<br>((pidl<br>= ::SHBrowseForFolder(&bi))<br>!=<br>NULL)<br> <br>{ <br> <br>::SHGetPathFromIDList(pidl, pszBuffer);<br> pMalloc->Free(pidl);<br> <br>}
pMalloc->Release();
FolderDir=pszBuffer;
}
}
void CAutoClickDlg::GetMultiFilePahtName(CString folder, CStringArray &files, CString filter)
{
CFileFind FFind;
CString
szDir
= folder;
if(szDir.Right(1)
!=
"\\\\")szDir
+=
"\\\\";
szDir
+=
filter;
BOOL Ressult
= FFind.FindFile(szDir);
CString Filepath;
while(Ressult)
{
Ressult = FFind.FindNextFile();
if(!FFind.IsDirectory()&&!FFind.IsDots())
{
Filepath=FFind.GetFilePath();
files.Add(Filepath);
}
}
FFind.Close();
}
2013-08-12
展开全部
不知道你指的批处理具体是什么操作?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询