#include <afx.h> ///MFC头文件须在前 #include <fstream> #define INPUTPATHSTR "corpus//*.txt" using namespace std; |
***************************************************************/
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();
}