1.枚舉全部文件夾(遞歸)php
void EnumerateFolders () { WIN32_FIND_DATA fd; HANDLE hFind = ::FindFirstFile (_T ("*.*"), &fd); if (hFind != INVALID_HANDLE_VALUE) { do { if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { CString name = fd.cFileName; if (name != _T (".") && name != _T ("..")) { TRACE (_T ("%s\n"), fd.cFileName); ::SetCurrentDirectory (fd.cFileName); EnumerateFolders (); ::SetCurrentDirectory (_T ("..")); } } } while (::FindNextFile (hFind, &fd)); ::FindClose (hFind); } }
//好比說枚舉E:\svn文件夾,不過可能會致使棧溢出
::SetCurrentDirectory(_T("e:\\svn"));
EnumerateFolders();
2.串行化類(版本控制http://www.vckbase.com/index.php/wv/1097)svn
class MyLine:public CObject { DECLARE_SERIAL(MyLine); public: MyLine(){}; MyLine(CPoint from,CPoint to){ m_ptFrom=from; m_ptTo=to; } void Serialize(CArchive &ar); protected: CPoint m_ptFrom; CPoint m_ptTo; }; IMPLEMENT_SERIAL(MyLine,CObject,1); void MyLine::Serialize(CArchive &ar){ if(ar.IsLoading()){ ar<<m_ptFrom<<m_ptTo; }else{ ar>>m_ptFrom>>m_ptTo; } }
下面是串行化輸入輸出demo:spa
void CMainWindow::OnFileWrite() { // TODO: 在此添加命令處理程序代碼 CFile file(_T("abc.txt"),CFile::modeCreate|CFile::modeWrite); CArchive ar(&file,CArchive::store); int i=10; float f=1.3f; char ch='c'; CString str=_T("abc"); ar<<i<<f<<ch<<str; } void CMainWindow::OnFileRead() { // TODO: 在此添加命令處理程序代碼 CFile file(_T("abc.txt"),CFile::modeRead); CArchive ar(&file,CArchive::load); int i; float f; char ch; CString str; CString strResult; ar>>i>>f>>ch>>str; //必須按順序輸出,也就是說存入的數據保持着原有的類型 strResult.Format(_T("%d,%f,%c,%s"),i,f,ch,str); AfxMessageBox(strResult); }