• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 488
  • Last Modified:

making a tree control out of a text file

my program extracts information from archive files and then saves them to a text file.the format for the text file is

12345678|12345678|12345678|Controls\FileName1.dat  <------ Thats how it looks like if you where to open the text file
12345678|12345678|12345678|Movies\FileName2.dat
12345678|12345678|12345678|Sound\English\FileName3.dat
12345678|12345678|12345678|Escape\Tree\FileName4.dat
ect
ect.....


Now what i want to do is read information from that text file and create a tree form that exands and so on. the name before the "\" is a folder and the FileName1.dat is obvisouly the file. So is there a way to skip the first 3 blocks of information and only read the last names and then create a explorer type tree ?
in theory,i am trying to make a "ISOBuster" type look with my own custom image type.
0
didifool213
Asked:
didifool213
  • 28
  • 21
  • 3
  • +1
2 Solutions
 
mahesh1402Commented:
You need to read contents of txt file in CString.. You may use CStdioFile MFC class for this.. After that you need to split path from CString.
Refer this CPathSplit class which allows you to parse string and seperate file name , drives and folders from it.
http://www.codeproject.com/string/CPathSplit.asp <==

Also refer SplitPath article : http://www.codeproject.com/file/SplitPath.asp


for fetching contents in treeview this may be of your use :

http://www.codeproject.com/treectrl/CFolderTreeCtrl.asp
http://www.codeproject.com/useritems/FileTreeCtrl.asp
http://www.codeproject.com/useritems/SimpleDrvExplorer.asp

MAHESH
0
 
didifool213Author Commented:
i have already checked those out.but what i am trying to do is read the text file and get the path from it, THEN make a tree control in my MFC app
0
 
mahesh1402Commented:
>>i have already checked those out.but what i am trying to do is read the text file and get the path from it, THEN make a tree control in my MFC app

For splitting path only this is of use :

http://www.codeproject.com/string/CPathSplit.asp
http://www.codeproject.com/file/SplitPath.asp

MAHESH
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
mahesh1402Commented:
and for reading text file and to retrieve string in CString use CStdioFile class. Use memeber function CStdioFile::ReadString() which will help you to get a text line in CString. AFter that use above CPathSplit class to split path.

MAHESH
0
 
didifool213Author Commented:
I am getting a bit confused.These links you are suggesting i already checked them out and they don't do what i am trying to. what im trying to do is

Build a GUI MFC app

has
1 - Tree Control -> m_tree
1- Edit field -> m_file
1- browse button to select my input file
1- populate button,once pressed it will read the text file and populate the tree box


-------
Could u give me a full example of how to use CStdioFile class or maybe even a tutorial, remember im still a newbie!

0
 
didifool213Author Commented:
http://i78.photobucket.com/albums/j100/player98198/tool.jpg

that is how my tool looks like right now.see how i am using a listbox instead of a tree.it is hard to distinguishe what file belongs to what folder when your dealing with alot of files.

hope that clears up what im trying to do.
0
 
mahesh1402Commented:
>>how to use CStdioFile class

CStdioFile infile;
CString buf;

 infile.Open( "C:\\Input.txt", CFile::modeRead | CFile::shareDenyNone ); //give your text file path
 
 while(infile.ReadString(buf))
{

// Do your extra porcessing here after read text line in buf..e.g. splitting path

 }

 infile.Close();


MAHESH
0
 
didifool213Author Commented:
could you show me how to use the splitpath function to filetree.that part is a bit confusing
0
 
mahesh1402Commented:
you may refer first parth of this article : http://www.codeproject.com/string/CPathSplit.asp

CString StrPath;
CPathSplit l_oPathSplit;

while(infile.ReadString(buf))
{

StrPath = buf;
l_oPathSplit.Split(StrPath); // split path

now you may use following to retrieve split path

CString strDrv,strDir,strFile,strExt;

strDrv=l_oPathSplit.GetDrive(); <== Get drive

strDir=l_oPathSplit.GetDirectory() <== Get directory

strFile=l_oPathSplit.GetFileName() <== Get File name

strExt=l_oPathSplit.GetExtension() <== get extension of file


MAHESH
0
 
mahesh1402Commented:
remember before using above you need to just download CSplitPath.h and CSplitPath.CPP files. Add them both in your project and include CSplitPath.h in your src file.

MAHESH
0
 
mahesh1402Commented:
and if u sound this class using too complicated then you may use functions from Shlwapi.lib

click here : http://www.codeproject.com/file/SplitPath.asp?df=100&forumid=208853&select=1209403#xx1209403xx

MAHESH
0
 
didifool213Author Commented:
i have added the header file already but i still am not able to get the information to the tree


void CMy6Dlg::OnButton2()
{
CStdioFile infile;
CString buf;
CString StrPath;
CPathSplit l_oPathSplit;

 infile.Open( m_file, CFile::modeRead | CFile::shareDenyNone ); //give your text file path
 
while(infile.ReadString(buf))
{

StrPath = buf;
l_oPathSplit.Split(StrPath); // split path

CString strDrv,strDir,strFile,strExt;

strDrv=l_oPathSplit.GetDrive(); //<== Get drive

strDir=l_oPathSplit.GetDirectory(); //<== Get directory

strFile=l_oPathSplit.GetFileName(); //<== Get File name

strExt=l_oPathSplit.GetExtension(); //<== get extension of file

m_tree   = m_oSplitter.GetDirectory(); //I want to get main directory atleast.so i made member variable
                                       //for the treecontrol.it is CTreeCtrl class

 }

 infile.Close();
      
}

but i get this error.how would i be able to take the information i get from PathSplit and forward it to the treecontrol?
 error C2582: 'CTreeCtrl' : 'operator =' function is unavailable
0
 
mahesh1402Commented:
didifool213 ,

I will sugest you to first refer how to use treeview control.....you cant assign tree control member variable like that . You need to use InsertItem() member function to insert item to treeview control.

e.g.
m_tree.InsertItem(m_oSplitter.GetDirectory());

But instead of directly trying this I will suggest you to refer this full treeview tutorial here:
http://www.functionx.com/visualc/controls/treectrl.htm

MAHESH

0
 
didifool213Author Commented:
im getting totally lost now ;(

http://s33.yousendit.com/d.aspx?id=24QNN2NEF08362PBOZ6WZOZOY8

there's link to the code im working wtih if your interested to walk me thru this.it might be simple problem but im a hardware guy and programming is prety new to me.but this app is really driving me crazy!

the test.txt file is in the debug folder it has a simple layout
0
 
mahesh1402Commented:
ok ! here you go.. DO like this now.....

forget about CPathSplit class.. remove all related from above src code....as its not working for your purpose !

download PathInfo.h and PathInfo.CPP from this link : http://www.codeproject.com/file/SplitPath.asp

include in your project. include header file in src. and in your loop of 6Dlg.CPP do this  :

void CMy6Dlg::OnButton2()
{
CStdioFile infile;
CString buf;
CString StrPath;


 infile.Open( m_file, CFile::modeRead | CFile::shareDenyNone ); //give your text file path
 CString strDrv,strDir,strFile,strExt;
while(infile.ReadString(buf))
{

StrPath = buf;


   m_file   = PathInfo:getDirectory(StrPath); //I want to get main directory atleast.so i made member variable

  HTREEITEM hPA = m_tree.InsertItem( _T(m_file), 0, 0,  NULL);
  m_tree.Expand(hPA, TVE_EXPAND);
 }

 infile.Close();
      
}

I have just tested this on your src and working fine.

REMEBER to remove all CSplitPath related stuff from your src code and then do above changes.


MAHESH
0
 
didifool213Author Commented:
ah,works! but now how do i add the leaf's on the tree? right now it just displays a full line of what was in the text file
0
 
mahesh1402Commented:
Now for treeview you need to read this full.. how to add subitems : http://www.functionx.com/visualc/controls/treectrl.htm

MAHESH
0
 
didifool213Author Commented:
ok, well you gota remember that the folders will not allways be the same.the names will change as well as the file names.
the part where it shuld turn into a leaf is when it see's a backslash "\" and then it shuld drop down and then read mroe of the file and if it see's it again..ect.ect

the tutorial does explain some great facts and stuff about treectrl but does not talk about delimiter's or whatnot
0
 
mahesh1402Commented:
also refer PathInfo::getFolder,PathInfo::getDrive,PathInfo::getName,PathInfo::getExtension etc functions.
0
 
mahesh1402Commented:
e.g
 m_file   = PathInfo::getName(StrPath); //I want to get main directory atleast.so i made member variable <== file name
0
 
didifool213Author Commented:
AH!!!
so, hmmmmmmmmm, well .sry but im still kind of confused on how to make this into a tree!!i can get one thing to display either name or directory but not both in

maindir
--->subdir
------->File1.dat
0
 
mahesh1402Commented:
to create subitems like folder in root and subitem as filename :

e.g
               HTREEITEM hfolder, hCompany;

      hTree = m_tree.InsertItem(PathInfo:getDirectory(StrPath), TVI_ROOT);
      
      hfile = m_tree.InsertItem(PathInfo::getName(StrPath), hTree);

MAHESH
0
 
mahesh1402Commented:
sorry read as :

 HTREEITEM hfolder, hfile;

     hTree = m_tree.InsertItem(PathInfo:getDirectory(StrPath), TVI_ROOT);
     
     hfile = m_tree.InsertItem(PathInfo::getName(StrPath), hTree);
0
 
mahesh1402Commented:
LOL again mistake ;-)

HTREEITEM hfolder, hfile;

hfolder = m_tree.InsertItem(PathInfo:getDirectory(StrPath), TVI_ROOT);
     
hfile = m_tree.InsertItem(PathInfo::getName(StrPath), hfolder);

MAHESH
0
 
didifool213Author Commented:
since there is multiple sub dir's then how would i code that? also what if i didn't know how many sub dir's there where.right now i have to declare the dir in order for it to be seen,but the text file has bout 3 diff sub dir's
0
 
puranik_pCommented:
CString str;
//read from file...

CStdioFile sfMyFile( m_strFileName, CFile::modeRead );  

//m_strFilename is filename containing a kind of data 12345678|12345678|12345678|Controls\FileName1.dat


//read each line of the file
while ( sfMyFile.ReadString( str ) )
{
     CString strText = strtok(str.GetBuffer(str.GetLength()), "|");
    int n=0;
    CString strTempText;
    while (strText !=NULL)
    {
          strText = strtok(NULL,"|");
          if (strText != NULL)
           strTempText = strText;
    }
   
   ///This gives you the value of strTempText = Controls\FileName1.dat

 //   You can retrieve the filename from this.
  int nPos = strTemtText.Find("\");
  CString strFileName = strTempText.Mid(nPos + 1,  strTempText.GetLength() -1 - nPos )
strFileName.TrimLeft();
strFileName.TrimRight();

//Now you have got the filename.
//You can find out the exact location of the file using FindFirstFile and FindNextFile functions for each drive.
///For this Reffer a link http://www.codeproject.com/Purgatory/baji_s_solution.asp

Once you have got the full path of the file FileName1.dat
read the file content using same method as given above.
and populate your treeview control.




 

 

 



}
sfMyFile.Close();
0
 
didifool213Author Commented:
c:\program files\microsoft visual studio\myprojects\test\6dlg.cpp(203) : error C2001: newline in constant
c:\program files\microsoft visual studio\myprojects\test\6dlg.cpp(204) : error C2146: syntax error : missing ')' before identifier 'CString'


void CMy6Dlg::OnButton1()
{
CString str;
//read from file...

CStdioFile sfMyFile( m_file, CFile::modeRead );  

//m_strFilename is filename containing a kind of data 12345678|12345678|12345678|Controls\FileName1.dat


//read each line of the file
while ( sfMyFile.ReadString( str ) )
{
     CString strText = strtok(str.GetBuffer(str.GetLength()), "|");
    int n=0;
    CString strTempText;
    while (strText !=NULL)
    {
          strText = strtok(NULL,"|");
          if (strText != NULL)
           strTempText = strText;
    }
   
   ///This gives you the value of strTempText = Controls\FileName1.dat

 //   You can retrieve the filename from this.
  int nPos = strTempText.Find("\");
  CString m_file = strTempText.Mid(nPos + 1,  strTempText.GetLength() -1 - nPos )
m_file.TrimLeft();
m_file.TrimRight();
}
sfMyFile.Close();
}
0
 
mahesh1402Commented:
int nPos = strTempText.Find("\"); <==== it should be "\\"

int nPos = strTempText.Find("\\");

MAHESH
0
 
didifool213Author Commented:
its just getting more an more confusing.
0
 
mahesh1402Commented:
also CString m_file = strTempText.Mid(nPos + 1,  strTempText.GetLength() -1 - nPos ) <== ';' missing

it shld be :

CString m_file = strTempText.Mid(nPos + 1,  strTempText.GetLength() -1 - nPos );

MAHESH
0
 
didifool213Author Commented:
yeah, i caugth that one! but now this is getting harder because i have two different solutions i guess.only thing is i don't know how to make them work at all.anyone wliling to finish the small code ,i learn from examples other wise im lost!

trying to get full path in a tree/leaf assortment

Root
->Sub1
>File1.dat
-->Sub2 (If sub2 exists)
----->File2.dat
0
 
mahesh1402Commented:
so now where r u stucked ?

you can retrieve tokens from path as on above code...each time in loop you are geting leafs in variable 'strTempText' put your insert item code after that...

while (strText !=NULL)
    {
          strText = strtok(NULL,"|");
          if (strText != NULL)
           strTempText = strText;

         //INSERT ITEMS TO TREEVIEW

   }

MAHESH
0
 
didifool213Author Commented:
void CMy6Dlg::OnButton1()
{

CString str;
//read from file...


m_tree.DeleteAllItems();

CStdioFile infile;
CString buf;
CString StrPath;


 infile.Open( m_file, CFile::modeRead | CFile::shareDenyNone ); //give your text file path
 CString strDrv,strDir,strFile,strExt;
while(infile.ReadString(buf))
{
HTREEITEM hdrv,hfolder, hsub1,hsub2,hsub3,hfile;
StrPath = buf;

m_file   = PathInfo::getDrive(StrPath);
m_path   = PathInfo::getDirectory(StrPath);

m_file   = PathInfo::getName(StrPath); //I want to get main directory atleast.so i made member variable <== file name



hfolder = m_tree.InsertItem(PathInfo::getDirectory(StrPath), TVI_ROOT);

     
hfile = m_tree.InsertItem(PathInfo::getName(StrPath), hfolder);




 // m_tree.Expand(hPA, TVE_EXPAND);


 






CStdioFile sfMyFile( m_strFileName, CFile::modeRead );  

//m_strFilename is filename containing a kind of data 12345678|12345678|12345678|Controls\FileName1.dat


//read each line of the file
while ( sfMyFile.ReadString( str ) )
{
     CString strText = strtok(str.GetBuffer(str.GetLength()), "|");
    int n=0;
    CString strTempText;
    while (strText !=NULL)
    {
          strText = strtok(NULL,"|");
          if (strText != NULL)
           strTempText = strText;


hfolder = m_tree.InsertItem(PathInfo::getDirectory(StrPath), TVI_ROOT);    
hfile = m_tree.InsertItem(PathInfo::getName(StrPath), hfolder);
    }

   ///This gives you the value of strTempText = Controls\FileName1.dat

 //   You can retrieve the filename from this.
  int nPos  = strTempText.Find("\\");
 
  CString strFileName = strTempText.Mid(nPos + 1,  strTempText.GetLength() -1 - nPos );
m_strFileName.TrimLeft();
m_strFileName.TrimRight();







HTREEITEM hPA = m_tree.InsertItem( _T(m_file), 0, 0,  NULL);
}
sfMyFile.Close();
infile.Close();
}
}


Thats what i put.when i press button it gives me insertion error and tool crashes
0
 
mahesh1402Commented:
CString strText = strtok(str.GetBuffer(str.GetLength()), "|"); <==== instead of this try :

char *strText =strtok(str.GetBuffer(str.GetLength()), "|");

MAHESH
0
 
didifool213Author Commented:
0
 
mahesh1402Commented:
didifool213 ,

you are making mistake..... above token related code is having NO relation with previous PathInfo class. Why did you mixed both loops ?? You just have to put token related code in loop and delete all previous PathInfo related code..


MAHESH
0
 
didifool213Author Commented:
Please can u give me an example.This is really hard for me since i don't know what im doing

void CMy6Dlg::OnButton1()
{

CString str;



CStdioFile sfMyFile( m_strFileName, CFile::modeRead );  

//m_strFilename is filename containing a kind of data 12345678|12345678|12345678|Controls\FileName1.dat


//read each line of the file
while ( sfMyFile.ReadString( str ) )
{
     //CString strText = strtok(str.GetBuffer(str.GetLength()), "|");
       char *strText =strtok(str.GetBuffer(str.GetLength()), "|");
    int n=0;
    CString strTempText;
    while (strText !=NULL)
    {
          strText = strtok(NULL,"|");
          if (strText != NULL)
           strTempText = strText;

    }

   ///This gives you the value of strTempText = Controls\FileName1.dat

 //   You can retrieve the filename from this.
  int nPos  = strTempText.Find("\\");
 
  CString strFileName = strTempText.Mid(nPos + 1,  strTempText.GetLength() -1 - nPos );
m_strFileName.TrimLeft();
m_strFileName.TrimRight();


HTREEITEM hPA = m_tree.InsertItem( _T(strFileName), 0, 0,  NULL);
 m_tree.Expand(hPA, TVE_EXPAND);
}
sfMyFile.Close();


}
0
 
mahesh1402Commented:
In above function :

char *strText =strtok(str.GetBuffer(str.GetLength()), "");  <== NOTE it shld be ""
    int n=0;
    CString strTempText;
    while (strText !=NULL)
    {
          strText = strtok(NULL,"|");
          if (strText != NULL)
           strTempText = strText;


          // Insert Tree Items HERE using strTempText <========================


   }
0
 
didifool213Author Commented:
no luck
0
 
mahesh1402Commented:
http://s63.yousendit.com/d.aspx?id=3GECIYKBCK9IS2O500JHUJ0QEO <== modified srccode with exe....test it..

its working fine for movielist.txt in Debug folder.

MAHESH
0
 
didifool213Author Commented:
ah great thank you! but how come there is multiple same named root dir's?
0
 
mahesh1402Commented:
in your text file movielist.txt Movies is only  root dir for all...change that and test it

MAHESH
0
 
didifool213Author Commented:
well yes that changes,but how come all the files don't fall under 1 single root dir instead of listing multiple's of the same dir?
0
 
mahesh1402Commented:
didifool213 ,

 this is sample program...as you have understood now how treeview works...just change root of item to put it anywhere..thats it...this is sample made for you to show how tokens work..u have to take care of other things your own.. as u know now how this can be done.....

MAHESH
0
 
mahesh1402Commented:
all u have to do it change root of items to put them appropriate under parent
0
 
DanRollinsCommented:
The first thing you need to do to get unconfused is to take a pencil and paper and draw what you wnt the tree to look like.   It sounds like you want a tree like:

Movies
    |--- English
    |        |----------- AVAttract.asp
    |        |----------- AVAttract.mps
    |        |----------- AVCampSiteIntro.asp
    |         \----------- AVCampSiteIntro.mpc
    |--- Subtitles
    |          |--- English
    |          |        |----------- AVCampSiteIntro.asp
    |          |         \----------- AVCampSiteIntro.mpc
    |          \---- French
    |                    |----------- AVCampSiteIntro.asp
    |                     \----------- AVCampSiteIntro.mpc
    |--- French
    |        |----------- AVdwOutro.asp
    |        \----------- AVdwOutro.asp
    |---- PackageArt
             |----------- AVAttract.JPG
             \----------- AVCampSiteIntro.JPG

Are you sure that's what you want?  For instance, I'd think that you want the a node like "AVAttract" to be a "folder" and then it would have nodes below it (for languages, subtitles, cover art, etc) with the actual filenames at the leafs.  And think about it:  Do you really want all of the "Subtitle" items in the same folder -- a jumble of subtitle files relating to many different movies?  Or don't you want the subtitles for a particular Movie to be listed below that movie name?

Think about these things and the DRAW the tree with pencil and paper.  
Provide a list of items  (say about 20) and
Provide a representation of what you want the resulting the tree to look like (see my example, above)

Once you are very clear as to how you want it to look, post back with that info and I'll help with the next step.

-- Dan
0
 
didifool213Author Commented:


Movies\English\AVdadaIntro.asf
Movies\English\AVdadaIntro.mpc
Movies\Subtitles\English\AVdadaIntro.stf

Movies\French\AVdadaOutro.asf
Movies\French\AVdadaOutro.mpc
Movies\Subtitles\French\AVdadaOutro.stf

Movies\Italian\AVdwIntro.asf
Movies\Italian\AVdwIntro.mpc
Movies\Subtitles\Italian\AVdwIntro.stf


Names with "[ ]" are folders

[Movies]
|
|--[English]
|  |
|  |-AVdadaIntro.asf       
|  |-AVdadaIntro.mpc
|
|--[French]
|  |
|  |-AVdadaOutro.asf
|  |-AVdadaOutro.mpc
|
|
|--[Italian]
|  |
|  |-AVdwIntro.asf
|  |-AVdwIntro.mpc
|
|
|
|
|--[Subtitles]
|  |
|  |-[English]
|  | |
|  | |-AVdadaIntro.stf
|  |
|  |-[French]
|  | |
|  | |-AVdadaOutro.stf
|  |
|  |-[Italian]
|  | |
|  | |-AVdwIntro.stf

Everything needs to fall under the [Movies] root dir.There needs to only be 1 [Subtitles] folder which has more sub dir's in it.If you need example of what tool needs to lok like than please check out www.isobuster.com 
Needs to have a kind of explorer type look or something easily readiable.
0
 
mahesh1402Commented:
didifool213 ,
 As I said now you have sample about how to extract tokens and also how to fetch them into treeview..As I have put it on right track from above code..
Now referring sample code from above links you can easilt make it urself...

http://www.codeproject.com/treectrl/CFolderTreeCtrl.asp
http://www.codeproject.com/useritems/FileTreeCtrl.asp
http://www.codeproject.com/useritems/SimpleDrvExplorer.asp


Remember experts here can redirect you towards right way..you should not expect fullfledge ready solution developed for you from them.

MAHESH
0
 
DanRollinsCommented:
mahesh1402,
It is easy to build a hierarchical tree from an existing hierarchical structure -- like the folder-and-files in a hard disk (as in all of the example code seen to date).  You just recurse through the hierarchy and let it guide you as you add the nodes to the tree.  

But the core of this problem is different -- it relates to creating a hierarchical structure from "flat" data.

=-=-=-=-=-=-=-=-=-=
didifool213,
Here is a narrative description of how I'd solve the problem:

I'd read the entire file into an array of strings -- stripping off the leading numbers.  Then sort the array (I added one item to the end).  It will now look like:

Movies\English\AVdadaIntro.asf
Movies\English\AVdadaIntro.mpc
Movies\French\AVdadaOutro.asf
Movies\French\AVdadaOutro.mpc
Movies\Italian\AVdwIntro.asf
Movies\Italian\AVdwIntro.mpc
Movies\Subtitles\English\AVdadaIntro.stf
Movies\Subtitles\French\AVdadaOutro.stf
Movies\Subtitles\Italian\AVdwIntro.stf
Movies\Zulu\AVdwEnetra.stf

Now, you read down the list and start to populate the tree.  As you process each line, break it into two pieces, the "path" and the "file"  

Path                                         File
Movies\English                          AVdadaIntro.asf
Movies\English                          AVdadaIntro.mpc
Movies\French                          AVdadaOutro.asf
Movies\French                          AVdadaOutro.mpc
Movies\Italian                           AVdwIntro.asf
Movies\Italian                           AVdwIntro.mpc
Movies\Subtitles\English            AVdadaIntro.stf
Movies\Subtitles\French            AVdadaOutro.stf
Movies\Subtitles\Italian             AVdwIntro.stf
Movies\Zulu                             AVdwEnetra.stf

First insert the root item (Movies)
And keep its hTreeItem as the "current parent" and set its icon to be a "folder"

Next look at the path part and see that it starts the same ("Movies") But it has an additional level ("English")   Since that is new, insert a new item and set its hParent to the "current parent" one and set its icon to be a "folder".  And now save THIS item's hTreeItem as the "current parent"

Next, see that you are done with the nodes of the "path" so all you need to do is insert the "file" ("AVdadaIntro.asf") and set its parent to the "current parent" and set it icon to indicate "document" (rather than "folder")

Now you continue to read down the list and as long as the path is the same, you will just insert under the "current parent"

When the path part changes (is different from the previous one) you will need to start a new folder.  The only trick will be deciding which folder is it's parent.  For instance, if the path changes from
      Movies\English
to
      Movies\French
Then you need to add a new child to the "Movies" folder and make that into the "current parent".  But if it changes from
     Movies\Subtitles\English
to
     Movies\Subtitles\French
You need to add a new child to the Subtitles folder which is a child of the Movies folder.  You could just "back up" by getting the parent folder for these examples.  But your system has to be smart enough to also handle situations like the change from:
     Movies\Subtitles\English
to
     Movies\Zulu

What I'd recommend is that at the path-changing-point, you look to the parent of the "current parent" and examine its text.  If the end-node of the path is the same, then you are done.   Otherwise, look to *that* node's parent...  At some point you will have backed up to "Movies" and realize that
     Movies\Zulu
will require a new "folder" node under Movies.

=-=-=-=-=-=-=-=
You can also do this without the initial sorting step:

As you read each line, break it into "path" and "file" as before.  
Add one or more folders, based on the parts of the "path."
As you add a folder node to the tree, save its full path in a CStringArray, with a parallel CUintArray that contains it HTREEITEM that resulted from the insert.

With each new line, search the CStringArray to see if the "path" has already been added.  If not, break off the last node and see if the resulting shorter path had been added... etc.  Once you find an existing "parent" (you always will, because "Movies" is in all of them) then you add folders as needed for that path (and add items to the CStringArray and CUintArray for each node added).

For instance after seven lines, your two arrays will look like:

CStringArray                    CUIntArray (HTREEITEM values)
================  =========
Movies                            0x12302340 (the HTREEITEM for the tree node)
Movies\English                 0x12302348
Movies\French                 0x12302400
Movies\Italian                  0x12302308
Movies\Subtitles               0x12305804
Movies\Subtitles\English    0x12302908

When you see
    Movies\Subtitles\French
in the input, you will not find it in the CStringArray.  So you shave off the last node ald look for
    Movies\Subtitles
which you *do* find.  The matching value in the CUIntArray will be the HTREEITEM of the parent for the new folder node.  You add that node in the tree and save its HTERRITAM and its string value ("Movies\Subtitles\French") for future comparisons.  Then add the "leaf" node ("AVdadaOutro.stf") under that.

=-=-=-=-=-=-=-=-=-=
It is a bit complicated...
That's because this question is about a data processing algorithm, not a rote use of an API.  If you need help understanding either of the techniques I described, then ask for clarification.  If you need help implementing, then do whatever part of it you can do, and I'll see if I can provide further help (without actually writing an entire implementation for you :-)

-- Dan
0
 
mahesh1402Commented:
>>It is easy to build a hierarchical tree from an existing hierarchical structure --

Dan,

Yes I know  that its not so difficult to build explorer like tree.. but what I suggested above is about providing ready solution for author for his custom needs.....if you read above complete comments....it seems he everytime expecting ready developed solution from experts as still I have provided extracting tokens related src and tree related src by modifying his src files.. Now he need to develop his own by this hints and help provided above as also algorithm suggested by you....

MAHESH
0
 
didifool213Author Commented:
Sorry guys I been to pushy.I am prety new to coding and im onto something but you gota understand that its hard for a new person to learn.I looked at all the sites you give me and it is still hard to understand where to put things.I ask for ready made stuff because i can learn like that, thats when i put the peice's togethor and thats how i figure it out.i do not copy your code,i actualy redo it till i get it and till it makes sense.my main goal is already made out and it is getting more and more difficult for me to reach it because there's so many obsticles in the way.it might be easy for you guys i know,since i am a hardware guy i know how easy fixing things is for me but for newbie's it is just a whole new world.i guess i now know how they feel eh :p
i really do appreciate the help that you guys are offering, and yes i have tried your method of reading the tutorials but still i run into problems that are same with one im facing now.
0
 
DanRollinsCommented:
didifool213,
There are two distinct problems here -- and both of them are difficult for a novice coder.

The first problem is getting to know all about how CTreeCtrl objects work.  This is like a carpenter getting to know his tools... he needs to know them so well that he can saw boards and hammer nails without asking which tool to use or how to use it.

One way to learn all about CTreeCtrl is to work through some of the tutorials and example code at the links that mahesh1402 has posted.  Make small changes... for instance, add a custom Imagelist to show your own icons.  Write a program that Inserts all of the items just the way you want for the nine-item example -- hard-coded... just to get the feel for how to do it.  That will teach you how child nodes are inserted and so forth.

The second problem is a pure data-processing problem and is, in itself, rather difficult, especially for a novice coder.   There are a number of ways to solve it, but all of them will require taking the time to understand the data -- the data analysis phase of the task.  Look for patterns... for instance, the end of the line is always a "leaf" node.  The next-to-end is its parent, so it is a "folder"  You will need to insert a folder node for it... but you can't do that until the right parent node exists for *it* so you will need to insert a parent node for it, until you have parent/child relationships all the way back to the root.  And you'll soon see that you must avoid inserting duplicates of existing folders, so you'll need to keep track of what's already been inserted.

I recommend that you work on the first task -- get to know how to populate a CTreeCtrl in a hard-coded hierarchy.  Get to a point where you really know the basics.  Try different tests.  Learn how to use the tool.  Only when you are at that point can you really make any headway on the second task.

-- Dan
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 28
  • 21
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now