Root directory file:
M_strrootpath.format (_t ("%ssyswsp"), __main_home__);
M_strrootpath is the root directory file path.
Example: WINDOWS\\:RELEASE\\:SYSWSP
Browerfile (0, M_strrootpath);
1 voidUmsdirectorytree::browerfile (LongCallnum, CString strfiles)2 {3callnum++;4 CFileFind Ffinder;5Strfiles + = _t ("\\*.*");6 7BOOL res =Ffinder.findfile (strfiles);8 while(RES)9 {Tenres =ffinder.findnextfile (); One if(Ffinder.isdirectory () &&!ffinder.isdots ()) A { -CString Strfilespath =Ffinder.getfilepath (); -CString Strfilesname =ffinder.getfilename (); the intpos = Strfilesname.find (_t ("@"),0); -M_strselectnode = Strfilesname.mid (pos+1); - Switch(Callnum) - { + Case 1: -M_strhtfir = M_tree.insertitem (m_strselectnode.getstring (),0,0, NULL); + Break; A Case 2: atM_strhtsec = M_tree.insertitem (m_strselectnode.getstring (),0,0, M_strhtfir); - Break; - Case 3: -M_strhtthr = M_tree.insertitem (m_strselectnode.getstring (),0,0, m_strhtsec); - Break; - Case 4: inM_strhtfou = M_tree.insertitem (m_strselectnode.getstring (),0,0, m_strhtthr); - Break; to Case 5: +M_strhtfif = M_tree.insertitem (m_strselectnode.getstring (),0,0, M_strhtfou); - Break; the default: *M_strhtsix = M_tree.insertitem (m_strselectnode.getstring (),0,0, M_strhtfir); $ Break;Panax Notoginseng } - browerfile (Callnum, strfilespath); the } + Else if(!ffinder.isdirectory () &&!ffinder.isdots ()) A { the CString Strwsppath; +Strwsppath =Ffinder.getfilepath (); -CString Strwspname =ffinder.getfilename (); $ intpos = Strwspname.find ((_t ("@")),0); $Strwspname = Strwspname.mid (pos+1); -pos = Strwspname.find (_t ("."),0); -M_strselectnode =Strwspname.left (POS); the - Switch(Callnum)Wuyi { the Case 1: -M_strhtroot = M_tree.insertitem (m_strselectnode.getstring (),0,0, NULL); Wu Break; - Case 2: AboutM_strhtend = M_tree.insertitem (m_strselectnode.getstring (),0,0, M_strhtfir); $ Break; - Case 3: -M_strhtend = M_tree.insertitem (m_strselectnode.getstring (),0,0, m_strhtsec); - Break; A Case 4: +M_strhtend = M_tree.insertitem (m_strselectnode.getstring (),0,0, m_strhtthr); the Break; - Case 5: $M_strhtend = M_tree.insertitem (m_strselectnode.getstring (),0,0, M_strhtfou); the Break; the default: theM_strhtsix = M_tree.insertitem (m_strselectnode.getstring (),0,0, m_strhtfif); the Break; - } in } the } the ffinder.close (); About}
Findnextfiles () is primarily responsible for finding subdirectories in each level of the node directory, whose return value is not 0, indicates that there are subdirectories and the return value is 0, indicating that the level directory already has no subdirectories.
All subdirectories in the level directory are traversed through the while () loop.
The while () loop body iterates through the next level of directory through a recursive call and inserts all directories at the next level through the switch branch structure into the previous node directory, so that the loop-recursive call will generate the tree.
Ctreectl Creating a directory tree