vc遍历文件夹
来源:互联网 发布:cctv网络直播电视台 编辑:程序博客网 时间:2024/06/06 05:19
#include <afx.h>
#include <afxwin.h> // MFC core and standard components
#include <afxext.h>
///MFC头文件须在前
#include <fstream>
#include <iostream>
#include <stdio.h>
#include <string>
#define INPUTPATHSTR "corpus//*.txt"
#define OUTPUTPATHSTR "result"
using namespace std;
int main()
{
string szFileNum,infileName,outfileName,strline;
CFileFind finder; //读所有的文件
BOOL bWorking = finder.FindFile(INPUTPATHSTR);
// ifstream in ; (infileName.c_str());
// ofstream out; (outfileName.c_str());
while (bWorking)
{
bWorking = finder.FindNextFile();
if(finder.IsDots())
continue;
if(!finder.IsDirectory())
{
CString CInputFileStr = finder.GetFilePath();//得到文件名
int NamePos = CInputFileStr.ReverseFind('//');
infileName = (LPCTSTR)CInputFileStr;
szFileNum = infileName.substr(NamePos, infileName.length() - NamePos + 1);
outfileName=OUTPUTPATHSTR+szFileNum;
ifstream in (infileName.c_str());
ofstream out(outfileName.c_str());
while (getline(in,strline))
{
out<<strline<<endl;
}
cout<<szFileNum<<" is processed!"<<endl;
in.close();
out.close();
}
}
finder.Close();
return 0;
}
***************************************************************/
void CLiuChunHongDlg::OnButton1()
{
// TODO: Add your control notification handler code here
CString strPath;
BROWSEINFO bi ={0};
char pszDisplayName[MAX_PATH] ="/0";
bi.hwndOwner=NULL;
bi.pszDisplayName = pszDisplayName;
bi.lpszTitle="请选择目录:";
bi.ulFlags=BIF_RETURNONLYFSDIRS;
LPITEMIDLIST lpIL = SHBrowseForFolder(&bi);
if(lpIL)
{
SHGetPathFromIDList(lpIL,bi.pszDisplayName);
}
else
{
strPath = _T("");
}
strPath = bi.pszDisplayName;
m_path=strPath;
UpdateData(FALSE);
}
void CLiuChunHongDlg::OnOK()
{
// TODO: Add extra validation here
CDialog::OnOK();
std::string szFileNum;
std::string strline;
std::string str;
int i;
CString houzhui="//*.txt";
CString INPUTPATHSTR=m_path+houzhui;
CFileFind finder; //读所有的文件
BOOL bWorking = finder.FindFile(INPUTPATHSTR);
// CString out_path="F://马龙//mycode//LiuChunHong//corpus2";
CStdioFile txt_cn,m_out;
while (bWorking)
{
CString out_path="F://马龙//mycode//LiuChunHong//corpus2";
bWorking = finder.FindNextFile();
if(finder.IsDots())
continue;
if(!finder.IsDirectory())
{
CString CInputFileStr = finder.GetFilePath();//得到文件名
int NamePos = CInputFileStr.ReverseFind('//');
szFileNum = (LPCTSTR)CInputFileStr;
szFileNum = szFileNum.substr(NamePos, szFileNum.length() - NamePos + 1);
const char* ptr=szFileNum.c_str();
CString b=ptr;
out_path=out_path+b;
char *out_path1=out_path.GetBuffer(out_path.GetLength());
char *cn_path = CInputFileStr.GetBuffer(CInputFileStr.GetLength());
txt_cn.Open(cn_path, CStdioFile::modeReadWrite);
m_out.Open(out_path1, CStdioFile::modeReadWrite|CStdioFile::modeCreate);
CString line_cn;
while(txt_cn.ReadString(line_cn))
{
//m_out.SeekToEnd();
if (!line_cn.IsEmpty())
{
i=line_cn.Find(" ");//find(" ");
//j=line_cn.GetLength();
line_cn.Delete(0,i+1);
m_out.WriteString(line_cn);
m_out.WriteString("/n");
}
else
{
m_out.WriteString("/n");
// out<<endl;
}
//m_out.WriteString(line_cn);
//m_out.WriteString("/n");
}
m_out.Close();
txt_cn.Close();
}
}
finder.Close();
}
- VC遍历文件夹,删除文件夹
- VC遍历文件夹
- vc 遍历文件夹
- vc遍历文件夹
- vc遍历文件夹
- vc 遍历文件夹,删除文件及文件夹!
- VC下遍历文件夹中的所有文件
- VC++遍历文件夹中的所有文件
- VC下遍历文件夹查找文件
- VC下遍历文件夹查找文件
- vc遍历文件夹下的所有文件
- VC枚举(遍历)文件夹里面的文件
- VC下遍历文件夹和文件
- 用VC遍历文件夹中的所有文件及文件夹
- VC遍历文件夹下所有文件和文件夹
- VC遍历文件夹下所有文件和文件夹
- VC遍历文件夹下所有文件和文件夹
- VC遍历文件夹下所有文件和文件夹
- 一起来学周易(5)——八卦的五行与方位
- 转: jsp:include vs include file
- join yield daemon
- vc_dll
- Windows系统自启动程序十大藏身之所
- vc遍历文件夹
- 一起来学周易(6)——十二地支与方位
- SQL Server全文索引
- 由了“动态堆栈”思考C
- kankan
- 删除数组中相同的元素 算法复杂度 O(nlogn)
- 使用sql server中的全文索引
- PHP 访问目录显示文件列表
- SQL Server 索引结构及其使用(一)