#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package (smart_init)
#pragma resource "*.DFM"
TForm1 *form1;
ttreenode* Currnode;
int dircount,filecount,drivecount;
//---------------------------------------------------------------------------
__fastcall Tform1::tform1 (tcomponent* Owner)
: Tform (Owner)
{
}
//---------------------------------------------------------------------------
void Tform1::treeinit (String path, Ttreenode * mynode)
{
Tsearchrec SR;
if (FindFirst (path+ "\\*.*", FAANYFILE,SR) ==0)
{
Todo
{
if (Sr. attr& fadirectory) ==fadirectory)
{
if (Sr. Name!= "." && Sr. Name!= "..")
{
Currnode=treeview1->items->addchild (MYNODE,SR. Name);
Treeinit (path+ "\" +SR). Name,currnode);
dircount++;
}
}
/*
Else
{
if (path. SubString (1,1) = = "A" | | Path. SubString (1,1) = = "B")
{
Currnode=treeview1->items->addchild (MYNODE,SR. Name);
filecount++;
}
}
*/
}
while (FindNext (SR) ==0);
}
}
//---------------------------------------------------------------------------
void __fastcall tform1::formcreate (tobject *sender)
{
String Drive,path;
dircount=filecount=0;
drivecount=drivecombobox1->items->count;
Treeview1->items->beginupdate ();
Treeview1->items->clear ();
Currnode=treeview1->items->add (treeview1->selected, "My Computer");
currnode->selected=true;
for (int i=0;i<drivecount;i++)
{
Drive=drivecombobox1->items->strings[i]. SubString (1,1);
Path=drive+ ":";
Currnode=treeview1->items->addchild (Treeview1->selected,drivecombobox1->items->strings[i]);
Treeinit (Path,currnode);
}
Treeview1->items->endupdate ();
}
//---------------------------------------------------------------------------
void __fastcall Tform1::treeview1click (tobject *sender)
{
int i;
String path;
Ttreenode *node;
node=treeview1->selected;
Get the current path selected by the user:
if (node->level)
{///when the user is not selecting a root node
Todo
{
if (node->level==1)
Path=node->text.substring (1,2) + (path. Length ()? " \ "": "") +path;
Else
path=node->text+ (path. Length ()? " \ "": "") +path;
node=node->parent;
}
while (Node->level);
To refresh the list view on the right:
Listview1->items->beginupdate ();
Listview1->items->clear ();
Tsearchrec SR;
if (FindFirst (path+ "\\*.*", FAANYFILE,SR) ==0)
{
Tlistitem *li;
Todo
{
if (Sr. Name!= "." && Sr. Name!= "..")
{
Li=listview1->items->add ();
LI->CAPTION=SR. Name;
if (Sr. Attr==fadirectory)
{
Li->subitems->add ("");
Li->subitems->add ("folder");
}
Else
{
Li->subitems->add (IntToStr (Sr. Size));
Li->subitems->add ("document");
}
Li->subitems->add (Filedatetodatetime (Sr. Time). dateTimeString ());
}
}
while (FindNext (SR) ==0);
FindClose (SR);
}
Listview1->alphasort ();
Listview1->items->endupdate ();
}
Else
{
Tlistitem *li;
Listview1->items->beginupdate ();
Listview1->items->clear ();
for (i=0;i<treeview1->selected->count;i++)
{
Li=listview1->items->add ();
li->caption=treeview1->selected->item[i]->text;
}
Listview1->items->endupdate ();
}
}
//---------------------------------------------------------------------------