|
|
|
|
#include "StdAfx.h"
|
|
|
|
|
#include "FileMgr.h"
|
|
|
|
|
#include "LogMgr.h"
|
|
|
|
|
#include "GlobalDefine.h"
|
|
|
|
|
#include "GlobalFunction.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if 1
|
|
|
|
|
void CCsvData::AddData(CString Str,bool bLineEnd)
|
|
|
|
|
{
|
|
|
|
|
m_StrVecTemp.push_back(Str);
|
|
|
|
|
if(bLineEnd)
|
|
|
|
|
{
|
|
|
|
|
m_DataVec.push_back(m_StrVecTemp);
|
|
|
|
|
m_StrVecTemp.clear();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CFileMgr::CFileMgr(void)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
CFileMgr::~CFileMgr(void)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
//<2F>Ե<EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>Ŀ¼Ϊ<C2BC><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><C2B7>(<28><><EFBFBD><EFBFBD>FilePath <20><>)
|
|
|
|
|
void CFileMgr::GetFullFilePath(char *FilePath,CString FileName)
|
|
|
|
|
{
|
|
|
|
|
CString str;
|
|
|
|
|
GetFullFilePath(str,FileName);
|
|
|
|
|
strcpy(FilePath,(LPSTR)(LPCTSTR)str);
|
|
|
|
|
}
|
|
|
|
|
//<2F>Ե<EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>Ŀ¼Ϊ<C2BC><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><C2B7>(FileName <20><>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\\Debug.txt)
|
|
|
|
|
void CFileMgr::GetFullFilePath(CString &FilePath,CString FileName)
|
|
|
|
|
{
|
|
|
|
|
CString sPath;
|
|
|
|
|
GetModuleFileName(NULL,sPath.GetBufferSetLength(1023),1024);
|
|
|
|
|
sPath.ReleaseBuffer();
|
|
|
|
|
int nPos;
|
|
|
|
|
nPos = sPath.ReverseFind('\\');
|
|
|
|
|
sPath = sPath.Left(nPos);
|
|
|
|
|
FilePath = sPath + FileName;
|
|
|
|
|
}
|
|
|
|
|
//<2F><>ȡ<EFBFBD><C8A1>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>Ŀ¼
|
|
|
|
|
CString CFileMgr::GetWorkPath()
|
|
|
|
|
{
|
|
|
|
|
CString sPath;
|
|
|
|
|
GetModuleFileName(NULL,sPath.GetBufferSetLength(1023),1024);
|
|
|
|
|
sPath.ReleaseBuffer();
|
|
|
|
|
int nPos;
|
|
|
|
|
nPos = sPath.ReverseFind('\\');
|
|
|
|
|
sPath = sPath.Left(nPos);
|
|
|
|
|
return sPath;
|
|
|
|
|
}
|
|
|
|
|
#if 1
|
|
|
|
|
#define Max_ReadFile_Times 5 //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD>ȡ<EFBFBD>ļ<EFBFBD><C4BC>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
//<2F><><EFBFBD>ж<EFBFBD>ȡFilePath ָ<><D6B8><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>浽vec <20><>(FilePath <20>dz<EFBFBD><C7B3><EFBFBD><EFBFBD><EFBFBD>Ŀ¼<C4BF>µ<EFBFBD><C2B5>ļ<EFBFBD>·<EFBFBD><C2B7>)
|
|
|
|
|
void CFileMgr::ReadFileToStringVec(const CString &FilePath,vector<CString> &vec)
|
|
|
|
|
{
|
|
|
|
|
for(int k=0;k<Max_ReadFile_Times;k++)
|
|
|
|
|
{
|
|
|
|
|
CStdioFile file;
|
|
|
|
|
if(file.Open(FilePath,CFile::modeRead,NULL))
|
|
|
|
|
{
|
|
|
|
|
CString str;
|
|
|
|
|
while(file.ReadString(str))
|
|
|
|
|
{
|
|
|
|
|
vec.push_back(str);
|
|
|
|
|
}
|
|
|
|
|
file.Close();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
CString Log = "File Open Err";
|
|
|
|
|
Log += FilePath;
|
|
|
|
|
gLogMgr->WriteDebugLog(Log);
|
|
|
|
|
Sleep(1000);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//<2F><>ȡ<EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>ÿһ<C3BF><D2BB>,<2C>Զ<EFBFBD><D4B6>ŷ<EFBFBD><C5B7><EFBFBD><EFBFBD><EFBFBD>ֵ
|
|
|
|
|
void CFileMgr::ReadFileToDoubleVec(const CString &FilePath,vector<vector<double>> &Vec)
|
|
|
|
|
{
|
|
|
|
|
//<2F><>ȡÿһ<C3BF><D2BB><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
|
|
|
|
|
vector<CString> StrVec;
|
|
|
|
|
ReadFileToStringVec(FilePath,StrVec);
|
|
|
|
|
vector<CString>::iterator iter = StrVec.begin();
|
|
|
|
|
vector<CString>::iterator iter_end = StrVec.end();
|
|
|
|
|
for(;iter!=iter_end;iter++)
|
|
|
|
|
{
|
|
|
|
|
vector<double> VecTmp;
|
|
|
|
|
//<2F><>str <20><><EFBFBD><EFBFBD>ȡdouble <20><>ֵ,<2C>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD>ָ<EFBFBD><D6B8><EFBFBD>
|
|
|
|
|
GetDoubleVal((*iter),VecTmp);
|
|
|
|
|
if(VecTmp.empty()==false)
|
|
|
|
|
Vec.push_back(VecTmp);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//<2F><>str <20><><EFBFBD><EFBFBD>ȡdouble <20><>ֵ,<2C>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD>ָ<EFBFBD><D6B8><EFBFBD>
|
|
|
|
|
void CFileMgr::GetDoubleVal(CString Str,vector<double> &Vec)
|
|
|
|
|
{
|
|
|
|
|
int CommaPosPer;//<2F><>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>ŵ<EFBFBD>λ<EFBFBD><CEBB>
|
|
|
|
|
CommaPosPer = Str.Find(",",0);
|
|
|
|
|
if(CommaPosPer == -1)//û<>ҵ<EFBFBD>ֱ<EFBFBD>ӷ<EFBFBD><D3B7><EFBFBD>
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
char *recvBuf = CStringToLPCSTR(Str);
|
|
|
|
|
//<2F><>һ<EFBFBD><D2BB>ֵ
|
|
|
|
|
double val = 0;
|
|
|
|
|
CString Str1(recvBuf,CommaPosPer);
|
|
|
|
|
val= atof(Str1);
|
|
|
|
|
Vec.push_back(val);
|
|
|
|
|
|
|
|
|
|
int idx = 0;
|
|
|
|
|
int CommaPosNext = CommaPosPer;
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
CommaPosNext = Str.Find(",",CommaPosPer+1);//<2F><>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>ŵ<EFBFBD>λ<EFBFBD><CEBB>
|
|
|
|
|
if(CommaPosNext==-1)//<2F><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>
|
|
|
|
|
{
|
|
|
|
|
CString Str1(recvBuf+CommaPosPer+1);
|
|
|
|
|
val= atof(Str1);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
CString Str1(recvBuf+CommaPosPer+1,CommaPosNext-CommaPosPer);
|
|
|
|
|
val= atof(Str1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Vec.push_back(val);
|
|
|
|
|
|
|
|
|
|
CommaPosPer = CommaPosNext;
|
|
|
|
|
idx++;
|
|
|
|
|
}while(CommaPosNext!=-1);
|
|
|
|
|
}
|
|
|
|
|
//<2F><>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD>뵽<EFBFBD>ı<EFBFBD><C4B1>ļ<EFBFBD>
|
|
|
|
|
void CFileMgr::WriteDbxyVecToFile(vector<Dbxy> &vec,CString Path)
|
|
|
|
|
{
|
|
|
|
|
ofstream file;
|
|
|
|
|
file.open(Path);
|
|
|
|
|
vector<Dbxy>::iterator iter = vec.begin();
|
|
|
|
|
vector<Dbxy>::iterator iter_end = vec.end();
|
|
|
|
|
for(;iter!=iter_end;iter++)
|
|
|
|
|
{
|
|
|
|
|
file<<(*iter).x<<","<<(*iter).y<<endl;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
#if 1
|
|
|
|
|
int CFileMgr::ReadFileToStrVec(const CString &FilePath,vector<vector<CString>> &Vec,bool bGapTab)
|
|
|
|
|
{
|
|
|
|
|
int EmptyLine = -1;
|
|
|
|
|
//<2F><>ȡÿһ<C3BF><D2BB><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
|
|
|
|
|
vector<CString> StrVec;
|
|
|
|
|
ReadFileToStringVec(FilePath,StrVec);
|
|
|
|
|
vector<CString>::iterator iter = StrVec.begin();
|
|
|
|
|
vector<CString>::iterator iter_end = StrVec.end();
|
|
|
|
|
for(int k=1;iter!=iter_end;iter++,k++)
|
|
|
|
|
{
|
|
|
|
|
vector<CString> VecTmp;
|
|
|
|
|
//<2F><>str <20><><EFBFBD><EFBFBD>ȡdouble <20><>ֵ,<2C>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD>ָ<EFBFBD><D6B8><EFBFBD>
|
|
|
|
|
GetStringVal((*iter),VecTmp,bGapTab);
|
|
|
|
|
if(VecTmp.empty()==false)
|
|
|
|
|
{
|
|
|
|
|
Vec.push_back(VecTmp);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
EmptyLine = k;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return EmptyLine;
|
|
|
|
|
}
|
|
|
|
|
//<2F><>str <20><><EFBFBD><EFBFBD>ȡval ֵ,<2C>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD>ָ<EFBFBD><D6B8><EFBFBD>
|
|
|
|
|
void CFileMgr::GetStringVal(CString Str,vector<CString> &Vec,bool bGapTab)
|
|
|
|
|
{
|
|
|
|
|
int CommaPosPer;//<2F><>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>ŵ<EFBFBD>λ<EFBFBD><CEBB>
|
|
|
|
|
if(bGapTab)
|
|
|
|
|
CommaPosPer = Str.Find(" ",0);
|
|
|
|
|
else
|
|
|
|
|
CommaPosPer = Str.Find(",",0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(CommaPosPer == -1)//û<>ҵ<EFBFBD>ֱ<EFBFBD>ӷ<EFBFBD><D3B7><EFBFBD>
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
char *recvBuf = CStringToLPCSTR(Str);
|
|
|
|
|
//<2F><>һ<EFBFBD><D2BB>ֵ
|
|
|
|
|
char gap = ',';
|
|
|
|
|
if(bGapTab)
|
|
|
|
|
gap = '\t';
|
|
|
|
|
CString Str1(recvBuf,CommaPosPer);
|
|
|
|
|
Str1.Remove(gap);//ɾ<><C9BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
Vec.push_back(Str1);
|
|
|
|
|
|
|
|
|
|
int idx = 0;
|
|
|
|
|
int CommaPosNext = CommaPosPer;
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
CString val;
|
|
|
|
|
CommaPosNext = Str.Find(gap,CommaPosPer+1);//<2F><>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>ŵ<EFBFBD>λ<EFBFBD><CEBB>
|
|
|
|
|
if(CommaPosNext==-1)//<2F><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>
|
|
|
|
|
{
|
|
|
|
|
CString Str1(recvBuf+CommaPosPer+1);
|
|
|
|
|
val = (Str1);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
CString Str1(recvBuf+CommaPosPer+1,CommaPosNext-CommaPosPer);
|
|
|
|
|
val = (Str1);
|
|
|
|
|
}
|
|
|
|
|
val.Remove(gap);//ɾ<><C9BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
Vec.push_back(val);
|
|
|
|
|
|
|
|
|
|
CommaPosPer = CommaPosNext;
|
|
|
|
|
idx++;
|
|
|
|
|
}while(CommaPosNext!=-1);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>(<28><><EFBFBD><EFBFBD>·<EFBFBD><C2B7>)
|
|
|
|
|
bool CFileMgr::IsFileExist(CString FilePath)
|
|
|
|
|
{
|
|
|
|
|
CFileFind finder;
|
|
|
|
|
bool bResult = finder.FindFile(FilePath);
|
|
|
|
|
finder.Close();
|
|
|
|
|
return bResult;
|
|
|
|
|
}
|
|
|
|
|
//Ŀ¼<C4BF>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
bool CFileMgr::IsDirectoryExists(CString const& path)
|
|
|
|
|
{
|
|
|
|
|
//<2F>ж<EFBFBD><D0B6>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
if(!PathFileExists(path))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
//<2F>ж<EFBFBD><D0B6>Ƿ<EFBFBD>ΪĿ¼
|
|
|
|
|
DWORD attributes = ::GetFileAttributes(path);
|
|
|
|
|
attributes &= FILE_ATTRIBUTE_DIRECTORY;
|
|
|
|
|
return attributes == FILE_ATTRIBUTE_DIRECTORY;
|
|
|
|
|
}
|
|
|
|
|
//<2F><>ȡ<EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>/<2F><><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>·<EFBFBD><C2B7>(Suffix Ϊָ<CEAA><D6B8><EFBFBD>ĺ<EFBFBD><EFBFBD><D7BA>)
|
|
|
|
|
void CFileMgr::GetChildFileOrDirName(bool bDir,CString strPath,vector <CString>& Vec,CString Suffix)
|
|
|
|
|
{
|
|
|
|
|
CString strFilePath;
|
|
|
|
|
int dwDirSize = 0;
|
|
|
|
|
strFilePath += strPath;
|
|
|
|
|
strFilePath += "//*.*";
|
|
|
|
|
CFileFind finder;
|
|
|
|
|
BOOL bFind = finder.FindFile(strFilePath);
|
|
|
|
|
while (bFind)
|
|
|
|
|
{
|
|
|
|
|
bFind = finder.FindNextFile();
|
|
|
|
|
if (!finder.IsDots())
|
|
|
|
|
{
|
|
|
|
|
CString strTempPath = finder.GetFilePath();
|
|
|
|
|
if(bDir && finder.IsDirectory())
|
|
|
|
|
{
|
|
|
|
|
Vec.push_back(strTempPath);
|
|
|
|
|
}
|
|
|
|
|
else if(!bDir)
|
|
|
|
|
{
|
|
|
|
|
if(Suffix != "")//ָ<><D6B8><EFBFBD>˺<EFBFBD>
|
|
|
|
|
{
|
|
|
|
|
if(strTempPath.Find(Suffix)!=-1)
|
|
|
|
|
Vec.push_back(strTempPath);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Vec.push_back(strTempPath);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
finder.Close();
|
|
|
|
|
}
|
|
|
|
|
//ɾ<><C9BE>ָ<EFBFBD><D6B8>Ŀ¼<C4BF>µ<EFBFBD><C2B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
|
|
|
|
|
void CFileMgr::DeleteDirFile(CString FilePath)
|
|
|
|
|
{
|
|
|
|
|
CString DelStr("del /s/q ");
|
|
|
|
|
DelStr += FilePath;
|
|
|
|
|
system(DelStr);
|
|
|
|
|
}
|
|
|
|
|
//ɾ<><C9BE>Ŀ¼
|
|
|
|
|
void CFileMgr::DeleteDir(CString DirPath)
|
|
|
|
|
{
|
|
|
|
|
CString DelStr("rmdir ");
|
|
|
|
|
DelStr += DirPath;
|
|
|
|
|
system(DelStr);
|
|
|
|
|
}
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>Ŀ¼(ֻ<>ø<EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ¼<C4BF><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һϵ<D2BB><CFB5>Ŀ¼<C4BF><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>)
|
|
|
|
|
void CFileMgr::CreatDir(CString DirPath)
|
|
|
|
|
{
|
|
|
|
|
if(!IsDirectoryExists(DirPath))
|
|
|
|
|
{
|
|
|
|
|
//CString MkdirCmd("mkdir ");
|
|
|
|
|
//MkdirCmd += DirPath;
|
|
|
|
|
//system(MkdirCmd);
|
|
|
|
|
|
|
|
|
|
CreateMultipleDirectory(DirPath);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>༶Ŀ¼
|
|
|
|
|
bool CFileMgr::CreateMultipleDirectory(const CString& szPath)
|
|
|
|
|
{
|
|
|
|
|
CString log="CreateMultipleDirectory->";
|
|
|
|
|
log += szPath;
|
|
|
|
|
gLogMgr->WriteDebugLog(log);
|
|
|
|
|
|
|
|
|
|
CString strDir(szPath);//<2F><><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ¼<C4BF>ַ<EFBFBD><D6B7><EFBFBD>
|
|
|
|
|
//ȷ<><C8B7><EFBFBD><EFBFBD>'\'<27><>β<EFBFBD>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>Ŀ¼
|
|
|
|
|
if (strDir.GetAt(strDir.GetLength()-1)!=_T('\\'))
|
|
|
|
|
{
|
|
|
|
|
strDir.AppendChar(_T('\\'));
|
|
|
|
|
}
|
|
|
|
|
std::vector<CString> vPath;//<2F><><EFBFBD><EFBFBD>ÿһ<C3BF><D2BB>Ŀ¼<C4BF>ַ<EFBFBD><D6B7><EFBFBD>
|
|
|
|
|
CString strTemp;//һ<><D2BB><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD>Ŀ¼<C4BF>ַ<EFBFBD><D6B7><EFBFBD>
|
|
|
|
|
bool bSuccess = false;//<2F>ɹ<EFBFBD><C9B9><EFBFBD>־
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
|
|
|
|
|
for (int i=0;i<strDir.GetLength();++i)
|
|
|
|
|
{
|
|
|
|
|
if (strDir.GetAt(i) != _T('\\'))
|
|
|
|
|
{//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>'\\'
|
|
|
|
|
strTemp.AppendChar(strDir.GetAt(i));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>'\\'
|
|
|
|
|
vPath.push_back(strTemp);//<2F><><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD><D3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
strTemp.AppendChar(_T('\\'));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ¼<C4BF><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD>ÿ<EFBFBD><C3BF>Ŀ¼
|
|
|
|
|
std::vector<CString>::const_iterator vIter;
|
|
|
|
|
for (vIter = vPath.begin(); vIter != vPath.end(); vIter++)
|
|
|
|
|
{
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>CreateDirectoryִ<79>гɹ<D0B3>,<2C><><EFBFBD><EFBFBD>true,<2C><><EFBFBD><EFBFBD>false
|
|
|
|
|
bSuccess = CreateDirectory(*vIter, NULL) ? true : false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
log = (bSuccess)?("Success"):("Error");
|
|
|
|
|
gLogMgr->WriteDebugLog(log);
|
|
|
|
|
return bSuccess;
|
|
|
|
|
}
|
|
|
|
|
//<2F><>Path1 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>copy <20><>Path2 (Ҳ<><D2B2><EFBFBD><EFBFBD><EFBFBD>ǵ<EFBFBD><C7B5><EFBFBD><EFBFBD>ļ<EFBFBD>)
|
|
|
|
|
void CFileMgr::CopyFile(CString Path1,CString Path2)
|
|
|
|
|
{
|
|
|
|
|
CString MoveFileCmd("copy ");
|
|
|
|
|
MoveFileCmd += Path1+" "+Path2;
|
|
|
|
|
//system(MoveFileCmd);
|
|
|
|
|
|
|
|
|
|
CopyFolder(Path1,Path2);
|
|
|
|
|
}
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>(<28><><EFBFBD><EFBFBD><EFBFBD>ĺ<DEB8><C4BA>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><C2B7>)
|
|
|
|
|
//FilePath<74><68><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>·<EFBFBD><C2B7>,NewName<6D><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
CString CFileMgr::FileReName(CString FilePath,CString NewName)
|
|
|
|
|
{
|
|
|
|
|
CString OldFilePath = FilePath;
|
|
|
|
|
|
|
|
|
|
CString Suffix = GetFileNameFromPath(FilePath,false);//<2F>к<EFBFBD>
|
|
|
|
|
CString FileName = GetFileNameFromPath(FilePath,true);//<2F><EFBFBD>
|
|
|
|
|
|
|
|
|
|
FilePath.Replace(Suffix,"");//<2F>õ<EFBFBD>·<EFBFBD><C2B7>
|
|
|
|
|
Suffix.Replace(FileName,"");//<2F>õ<EFBFBD><C3B5><EFBFBD>
|
|
|
|
|
CString NewFilePath = FilePath + NewName + Suffix;
|
|
|
|
|
//CFile::Rename(OldFilePath, NewFilePath);
|
|
|
|
|
|
|
|
|
|
ReNameFolder(OldFilePath,NewFilePath);
|
|
|
|
|
|
|
|
|
|
return NewFilePath;
|
|
|
|
|
}
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>Ŀ¼
|
|
|
|
|
void CFileMgr::OpenDir(CString DirPath)
|
|
|
|
|
{
|
|
|
|
|
if(IsDirectoryExists(DirPath))
|
|
|
|
|
{
|
|
|
|
|
ShellExecute(0,"open",DirPath,"","",SW_SHOWNORMAL);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//<2F><>·<EFBFBD><C2B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>(bDelSuffix ȥ<><C8A5><EFBFBD><EFBFBD>)
|
|
|
|
|
CString CFileMgr::GetFileNameFromPath(CString Path,bool bDelSuffix)
|
|
|
|
|
{
|
|
|
|
|
CString name = Path;
|
|
|
|
|
int idx = name.ReverseFind('\\');
|
|
|
|
|
if(idx != -1)
|
|
|
|
|
{
|
|
|
|
|
int len = name.GetLength();
|
|
|
|
|
name = name.Right(len - idx -1);
|
|
|
|
|
}
|
|
|
|
|
if(bDelSuffix)
|
|
|
|
|
{
|
|
|
|
|
idx = name.ReverseFind('.');
|
|
|
|
|
if(idx != -1)
|
|
|
|
|
{
|
|
|
|
|
int len = name.GetLength();
|
|
|
|
|
name = name.Left(len - (len-idx));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return name;
|
|
|
|
|
}
|
|
|
|
|
//<2F><EFBFBD><DEB8>ļ<EFBFBD><C4BC><EFBFBD>/ <20>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
BOOL CFileMgr::ReNameFolder(LPCTSTR lpszFromPath,LPCTSTR lpszToPath)
|
|
|
|
|
{
|
|
|
|
|
int nLengthFrm = strlen(lpszFromPath);
|
|
|
|
|
char *NewPathFrm = new char[nLengthFrm+2];
|
|
|
|
|
strcpy(NewPathFrm,lpszFromPath);
|
|
|
|
|
NewPathFrm[nLengthFrm] = '\0';
|
|
|
|
|
NewPathFrm[nLengthFrm+1] = '\0';
|
|
|
|
|
SHFILEOPSTRUCT FileOp;
|
|
|
|
|
ZeroMemory((void*)&FileOp,sizeof(SHFILEOPSTRUCT));
|
|
|
|
|
FileOp.fFlags = FOF_NOCONFIRMATION ;
|
|
|
|
|
FileOp.hNameMappings = NULL;
|
|
|
|
|
FileOp.hwnd = NULL;
|
|
|
|
|
FileOp.lpszProgressTitle = NULL;
|
|
|
|
|
FileOp.pFrom = NewPathFrm;
|
|
|
|
|
FileOp.pTo = lpszToPath;
|
|
|
|
|
FileOp.wFunc = FO_RENAME;
|
|
|
|
|
return SHFileOperation(&FileOp) == 0;
|
|
|
|
|
}
|
|
|
|
|
//<2F>ƶ<EFBFBD><C6B6>ļ<EFBFBD>/Ŀ¼
|
|
|
|
|
BOOL CFileMgr::MoveFolder(LPCTSTR lpszFromPath,LPCTSTR lpszToPath)
|
|
|
|
|
{
|
|
|
|
|
int nLengthFrm = strlen(lpszFromPath);
|
|
|
|
|
char *NewPathFrm = new char[nLengthFrm+2];
|
|
|
|
|
strcpy(NewPathFrm,lpszFromPath);
|
|
|
|
|
NewPathFrm[nLengthFrm] = '\0';
|
|
|
|
|
NewPathFrm[nLengthFrm+1] = '\0';
|
|
|
|
|
SHFILEOPSTRUCT FileOp;
|
|
|
|
|
ZeroMemory((void*)&FileOp,sizeof(SHFILEOPSTRUCT));
|
|
|
|
|
FileOp.fFlags = FOF_NOCONFIRMATION ;
|
|
|
|
|
FileOp.hNameMappings = NULL;
|
|
|
|
|
FileOp.hwnd = NULL;
|
|
|
|
|
FileOp.lpszProgressTitle = NULL;
|
|
|
|
|
FileOp.pFrom = NewPathFrm;
|
|
|
|
|
FileOp.pTo = lpszToPath;
|
|
|
|
|
FileOp.wFunc = FO_MOVE;
|
|
|
|
|
return SHFileOperation(&FileOp) == 0;
|
|
|
|
|
}
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>/Ŀ¼
|
|
|
|
|
BOOL CFileMgr::CopyFolder(LPCTSTR lpszFromPath,LPCTSTR lpszToPath)
|
|
|
|
|
{
|
|
|
|
|
int nLengthFrm = strlen(lpszFromPath);
|
|
|
|
|
char *NewPathFrm = new char[nLengthFrm+2];
|
|
|
|
|
strcpy(NewPathFrm,lpszFromPath);
|
|
|
|
|
NewPathFrm[nLengthFrm] = '\0';
|
|
|
|
|
NewPathFrm[nLengthFrm+1] = '\0';
|
|
|
|
|
SHFILEOPSTRUCT FileOp;
|
|
|
|
|
ZeroMemory((void*)&FileOp,sizeof(SHFILEOPSTRUCT));
|
|
|
|
|
FileOp.fFlags = FOF_NOCONFIRMATION ;
|
|
|
|
|
FileOp.hNameMappings = NULL;
|
|
|
|
|
FileOp.hwnd = NULL;
|
|
|
|
|
FileOp.lpszProgressTitle = NULL;
|
|
|
|
|
FileOp.pFrom = NewPathFrm;
|
|
|
|
|
FileOp.pTo = lpszToPath;
|
|
|
|
|
FileOp.wFunc = FO_COPY;
|
|
|
|
|
return SHFileOperation(&FileOp) == 0;
|
|
|
|
|
}
|
|
|
|
|
//ɾ<><C9BE><EFBFBD>ļ<EFBFBD>/Ŀ¼
|
|
|
|
|
BOOL CFileMgr::DeleteFolder(LPCTSTR lpszPath)
|
|
|
|
|
{
|
|
|
|
|
int nLength = strlen(lpszPath);
|
|
|
|
|
char *NewPath = new char[nLength+2];
|
|
|
|
|
strcpy(NewPath,lpszPath);
|
|
|
|
|
NewPath[nLength] = '\0';
|
|
|
|
|
NewPath[nLength+1] = '\0';
|
|
|
|
|
SHFILEOPSTRUCT FileOp;
|
|
|
|
|
ZeroMemory((void*)&FileOp,sizeof(SHFILEOPSTRUCT));
|
|
|
|
|
FileOp.fFlags = FOF_NOCONFIRMATION;
|
|
|
|
|
FileOp.hNameMappings = NULL;
|
|
|
|
|
FileOp.hwnd = NULL;
|
|
|
|
|
FileOp.lpszProgressTitle = NULL;
|
|
|
|
|
FileOp.pFrom = NewPath;
|
|
|
|
|
FileOp.pTo = NULL;
|
|
|
|
|
FileOp.wFunc = FO_DELETE;
|
|
|
|
|
return SHFileOperation(&FileOp) == 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BOOL CFileMgr::CopyDirOrFile(CString src,CString dest) //<2F><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>
|
|
|
|
|
{
|
|
|
|
|
char pFrom[256]{};
|
|
|
|
|
char pTo[256]{};
|
|
|
|
|
strcpy(pFrom, src); // <20><>һ<EFBFBD><D2BB><EFBFBD>ļ<EFBFBD>
|
|
|
|
|
strcpy(pTo, dest); // <20><>һ<EFBFBD><D2BB><EFBFBD>ļ<EFBFBD>
|
|
|
|
|
|
|
|
|
|
SHFILEOPSTRUCT sfo;
|
|
|
|
|
sfo.hwnd = NULL;
|
|
|
|
|
sfo.wFunc = FO_COPY;
|
|
|
|
|
sfo.pFrom = src;
|
|
|
|
|
sfo.pTo = dest;
|
|
|
|
|
sfo.fFlags = FOF_SILENT | FOF_NOCONFIRMATION | FOF_NOCONFIRMMKDIR;
|
|
|
|
|
|
|
|
|
|
return (SHFileOperation(&sfo)==0);//ִ<>гɹ<D0B3><C9B9><EFBFBD><EFBFBD><EFBFBD>0
|
|
|
|
|
}
|
|
|
|
|
#if 1
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD>CSV<53>ļ<EFBFBD>
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>DirPath "E:\LaipuLaserData\MonitoringData\WaferProcessData\2021\05\174357_FP03563_Port1_Slot3\"
|
|
|
|
|
//FileNameû<65>к<EFBFBD>,bAppend <>ӷ<EFBFBD>ʽд<CABD><D0B4>
|
|
|
|
|
void CFileMgr::WriteDataToExcel(CString DirPath,CString FileName,CCsvData &CsvData,bool bAppend)
|
|
|
|
|
{
|
|
|
|
|
CString FilePath = DirPath;
|
|
|
|
|
FilePath += FileName;
|
|
|
|
|
FilePath += ".xlsx";
|
|
|
|
|
|
|
|
|
|
ofstream fstream;
|
|
|
|
|
if(bAppend)//<><D7B7>д<EFBFBD><D0B4>
|
|
|
|
|
fstream.open(FilePath, ios::app);
|
|
|
|
|
else
|
|
|
|
|
fstream.open(FilePath);
|
|
|
|
|
|
|
|
|
|
vector<vector<CString>> &DataVec = CsvData.m_DataVec;
|
|
|
|
|
int size = DataVec.size();
|
|
|
|
|
for(int k=0;k<size;k++)
|
|
|
|
|
{
|
|
|
|
|
vector<CString>&StrVec = DataVec[k];
|
|
|
|
|
int size1 = StrVec.size();
|
|
|
|
|
for(int i=0;i<size1;i++)
|
|
|
|
|
{
|
|
|
|
|
fstream<<StrVec[i];
|
|
|
|
|
if(i<(size1-1))
|
|
|
|
|
{
|
|
|
|
|
fstream<<" ";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
fstream<<"\n";//<2F><><EFBFBD><EFBFBD>
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|