根目录文件:
m_strRootPath.Format(_T("%ssyswsp"), __main_home__);
m_strRootPath存放的是根目录文件路径。
例如:Windows\\:release\\:syswsp
BrowerFile(0, m_strRootPath);
1 void UMSDirectoryTree::BrowerFile(long CallNum, CString strFiles) 2 { 3 CallNum++; 4 CFileFind fFinder; 5 strFiles += _T("\\*.*"); 6 7 BOOL res = fFinder.FindFile(strFiles); 8 while(res) 9 { 10 res = fFinder.FindNextFile(); 11 if(fFinder.IsDirectory()&&!fFinder.IsDots()) 12 { 13 CString strFilesPath = fFinder.GetFilePath(); 14 CString strFilesName = fFinder.GetFileName(); 15 int pos = strFilesName.Find(_T("@"), 0); 16 m_strSelectNode = strFilesName.Mid(pos+1); 17 switch(CallNum) 18 { 19 case 1: 20 m_strHTFir = m_Tree.InsertItem(m_strSelectNode.GetString(), 0, 0, NULL); 21 break; 22 case 2: 23 m_strHTSec = m_Tree.InsertItem(m_strSelectNode.GetString(), 0, 0, m_strHTFir); 24 break; 25 case 3: 26 m_strHTThr = m_Tree.InsertItem(m_strSelectNode.GetString(), 0, 0, m_strHTSec); 27 break; 28 case 4: 29 m_strHTFou = m_Tree.InsertItem(m_strSelectNode.GetString(), 0, 0, m_strHTThr); 30 break; 31 case 5: 32 m_strHTFif = m_Tree.InsertItem(m_strSelectNode.GetString(), 0, 0, m_strHTFou); 33 break; 34 default: 35 m_strHTSix = m_Tree.InsertItem(m_strSelectNode.GetString(), 0, 0, m_strHTFir); 36 break; 37 } 38 BrowerFile(CallNum, strFilesPath); 39 } 40 else if(!fFinder.IsDirectory()&&!fFinder.IsDots()) 41 { 42 CString strwspPath; 43 strwspPath = fFinder.GetFilePath(); 44 CString strwspName = fFinder.GetFileName(); 45 int pos = strwspName.Find((_T("@")), 0); 46 strwspName = strwspName.Mid(pos+1); 47 pos = strwspName.Find(_T("."), 0); 48 m_strSelectNode = strwspName.Left(pos); 49 50 switch(CallNum) 51 { 52 case 1: 53 m_strHTRoot = m_Tree.InsertItem(m_strSelectNode.GetString(), 0, 0, NULL); 54 break; 55 case 2: 56 m_strHTEnd = m_Tree.InsertItem(m_strSelectNode.GetString(), 0, 0, m_strHTFir); 57 break; 58 case 3: 59 m_strHTEnd = m_Tree.InsertItem(m_strSelectNode.GetString(), 0, 0, m_strHTSec); 60 break; 61 case 4: 62 m_strHTEnd = m_Tree.InsertItem(m_strSelectNode.GetString(), 0, 0, m_strHTThr); 63 break; 64 case 5: 65 m_strHTEnd = m_Tree.InsertItem(m_strSelectNode.GetString(), 0, 0, m_strHTFou); 66 break; 67 default: 68 m_strHTSix = m_Tree.InsertItem(m_strSelectNode.GetString(), 0, 0, m_strHTFif); 69 break; 70 } 71 } 72 } 73 fFinder.Close(); 74 }
FindNextFiles()主要负责在每一级节点目录中寻找子目录,其返回值为非0,则表示还有子目录,返回值为0,则表示该级目录已经没有子目录了。
通过While()循环将遍历该级目录中所有的子目录。
While()循环体中将通过递归调用遍历下一级目录,并通过Switch分支结构将下一级所有目录插入上一级节点目录中,这样循环加递归调用将生成目录树。
时间: 2024-10-15 23:47:26