Example #1
0
void CEmoticonRichEditCtrl::FileFindRecurse(LPCTSTR pstr)
{	
	BOOL bWorking = FALSE;
	CFileFind finder;
	

	bWorking = finder.FindFile(pstr);	

	if(bWorking )
	{
		bWorking = finder.FindNextFile();		

		if (finder.IsDots() == FALSE && finder.IsDirectory()==FALSE)
		{
			TRACE("file\n");			
			m_strFileAll =  m_strFileAll + CString(pstr) + "|";
			m_nFileCnt++;
		}
		else 
		if (finder.IsDots() == TRUE || finder.IsDirectory()==TRUE)		
		{			
			CString strWildcard(pstr);
			strWildcard += _T("\\*.*");			
			
			bWorking = finder.FindFile(strWildcard);
			
			while (bWorking)
			{
				bWorking = finder.FindNextFile();
												
				if (finder.IsDots())
					continue;
				
				// if it's a directory, recursively search it

				if (finder.IsDirectory())
				{	
					// 폴더이면
					CString str = finder.GetFilePath();
					FileFindRecurse(str);
				}else{
					// 피일이면 (구하는 문자열)
					CString str = finder.GetFilePath();
					m_strFileAll = m_strFileAll + str + "|";// '|' 구분자는 파일경로단위
					m_nFileCnt++;
				}
			} // end of While			
		}		
	}
	finder.Close();
	
}
Example #2
0
/********************************************************
getLatestLogFileName --	find file with right extension and latest *creation* time stamp
// Last written timestamp not good enough, since depending on OS(!) and handle handling, write timestamp may not be updated until closing of file...
********************************************************/
CString getLatestLogFileName(CString logPath,CString fileExtension, CString SpecificFile) {

	CString fileName;
	CFileFind finder;
	CString candidate;
	CTime candidateCreationTime,fileNameCreationTime;
	char singleChar;

	//Check if a specific file is configured.If so, no work to be done
	if (SpecificFile!="") {
		return SpecificFile;
	}

	//	build a string with wildcards
	CString	strWildcard(logPath);
	strWildcard	+= _T("\\*");

	if (fileExtension!="") {
		singleChar=fileExtension.GetAt(0);
		if (singleChar!='.')	{
			strWildcard += _T(".");
		}
		strWildcard	+= _T(fileExtension);
	}

	// start searching for files
	BOOL bWorking = finder.FindFile(strWildcard);

	while (bWorking) {

		bWorking = finder.FindNextFile(); //must be called according to spec before finding any file..

		// skip .	and	.. files; otherwise, we'd recur infinitely!
		if (finder.IsDots())
			continue;

		//Get file info
		candidate=finder.GetFileName();
		finder.GetCreationTime(candidateCreationTime);

		if ((fileName=="")||(candidateCreationTime>fileNameCreationTime)) {
			fileName=candidate;
			fileNameCreationTime=candidateCreationTime;
		}
	}

	if (fileName=="") return fileName; //If no valid file at all.
	fileName=logPath + "\\" + fileName;
	return fileName;
}
Example #3
0
CXMLParser::CXMLParser(const std::string& fileStr)
{
#pragma region Create temp folder
	CString szFolder;
	LPITEMIDLIST pidl;
	LPMALLOC pShellMalloc;
	TCHAR szTemp[MAX_PATH];
	if(SUCCEEDED(SHGetMalloc(&pShellMalloc)))
	{
		if(SUCCEEDED(SHGetSpecialFolderLocation(NULL,
			CSIDL_APPDATA,&pidl)))
		{
			SHGetPathFromIDList(pidl,szTemp);
			szFolder =szTemp;
			pShellMalloc->Free(pidl);
		}
		pShellMalloc->Release();
	}

	szFolder.TrimRight(_T("\\"));
	szFolder += _T("\\TF3DXML");
	MyDeleteFile(szFolder);
	CFileStatus fstatus;
	if (!CFile::GetStatus(szFolder,fstatus))
	{
		::CreateDirectory(szFolder,NULL);
	}

#pragma endregion Create temp folder

	const size_t strsize=(szFolder.GetLength()+1)*2; // 宽字符的长度;
	char * qstr= new char[strsize]; //分配空间;
	size_t sz=0;
	wcstombs_s(&sz,qstr,strsize,szFolder,_TRUNCATE);

	cUnpackFile unpackTool;
	unpackTool.CreateDirFromZip(qstr,fileStr.c_str());
	delete []qstr;
	//delete []filestr;

	CFileFind finder;
	LPCTSTR pstr = szFolder;
	CString strWildcard(pstr);
	strWildcard += _T("\\*.*");
	CString m_ext_now;
	m_ext_now.Format(_T("%s"),_T("3DRep"));
	CString m_str_3dxml;	//查找装配树的.3dxml文件
	m_str_3dxml.Format(_T("%s"),_T("3dxml"));
	BOOL bWorking = finder.FindFile(strWildcard);
	while (bWorking)
	{
		bWorking = finder.FindNextFile();

		CString name = finder.GetFileName();
		CString extend = name.Right(name.GetLength() - name.ReverseFind('.') - 1);
		if(!finder.IsDots())
		{
			if (extend == m_ext_now)//m_ext_now为你要查找的文件扩展名
			{
				CString str=finder.GetFilePath();
				// 先得到要转换为字符的长度
				const size_t strsize=(str.GetLength()+1)*2; // 宽字符的长度;
				char * pstr= new char[strsize]; //分配空间;
				size_t sz=0;
				wcstombs_s(&sz,pstr,strsize,str,_TRUNCATE);

				TiXmlDocument *myDocument = new TiXmlDocument(pstr);
				myDocument->LoadFile();
				TiXmlElement *rootElement=myDocument->RootElement();
				if(rootElement->FirstChildElement()->FirstChildElement()!=NULL && strcmp(rootElement->FirstChildElement()->FirstChildElement()->Value(),"Rep")==0)
				{
					m_pTempFile=new TF3DRepFile();
					string filename;
					CT2A xx(name);
					filename = xx;
					m_pTempFile->SetFileName(filename);
					TraverseRep(rootElement->FirstChildElement()->FirstChildElement());
					m_fileList.push_back(m_pTempFile);
				}
				delete myDocument;
				delete []pstr;
			}
			if(extend == m_str_3dxml)
			{
				CString str=finder.GetFilePath();
				// 先得到要转换为字符的长度
				const size_t strsize=(str.GetLength()+1)*2; // 宽字符的长度;
				char * pstr= new char[strsize]; //分配空间;
				size_t sz=0;
				wcstombs_s(&sz,pstr,strsize,str,_TRUNCATE);

				TiXmlDocument *myDocument = new TiXmlDocument(pstr);
				myDocument->LoadFile();
				TiXmlElement *rootElement=myDocument->RootElement();
				if(strcmp(rootElement->FirstChildElement()->NextSiblingElement()->Value(),"ProductStructure")==0)
				{
					rootElement=rootElement->FirstChildElement()->NextSiblingElement()->FirstChildElement();
					m_root=new ReferenceTreeElement();
					m_root->value=(char *)rootElement->FirstAttribute()->Next()->Next()->Value();
					m_root->id=atoi(rootElement->FirstAttribute()->Next()->Value());
					m_root->instancename="";
					m_root->FirstChildElement=NULL;
					m_root->NextSimblingElement=NULL;
					while(rootElement!=NULL)
					{
						if(strcmp(rootElement->Value(),"Reference3D")==0)
						{
							AddReference3D(rootElement);
						}
						if(strcmp(rootElement->Value(),"Instance3D")==0)
						{
							AddInstance3D(rootElement);
						}
						rootElement=rootElement->NextSiblingElement();
					}
					FindAllTreeNode();
					ReferenceTreeElement *p=m_root;
					LinkTreeNode(p,NULL);
				}
			}
		}
	}

	finder.Close();

	MyDeleteFile(szFolder);
}