Browse a piece of code for a file

Source: Internet
Author: User
Tags addchild

#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-&GT;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 ();
}
}
//---------------------------------------------------------------------------

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.