用户登录  |  用户注册
首 页商业源码原创产品编程论坛
当前位置:PB创新网文章中心编程技巧C++ Builder

浏览文件的一段代码

减小字体 增大字体 作者:佚名  来源:本站整理  发布时间:2009-03-16 20:39:30

#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)
{
do
{
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,"我的电脑");
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;
//得到用户选择的当前路径:
if(node->Level)
{//当用户选择的不是根节点时
do
{
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);
//刷新右边的列表视图:
ListView1->Items->BeginUpdate();
ListView1->Items->Clear();
TSearchRec sr;
if(FindFirst(path+"\*.*",faAnyFile,sr)==0)
{
TListItem *li;
do
{
if(sr.Name!="." && sr.Name!="..")
{
li=ListView1->Items->Add();
li->Caption=sr.Name;
if(sr.Attr==faDirectory)
{
li->SubItems->Add("");
li->SubItems->Add("文件夹");
}
else
{
li->SubItems->Add(IntToStr(sr.Size));
li->SubItems->Add("文件");
}
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();
}
}
//---------------------------------------------------------------------------

Tags:

作者:佚名

文章评论评论内容只代表网友观点,与本站立场无关!

   评论摘要(共 0 条,得分 0 分,平均 0 分) 查看完整评论

相关文章

PB创新网ourmis.com】Copyright © 2000-2009 . All Rights Reserved .
页面执行时间:44,312.50000 毫秒
Email:ourmis@126.com QQ:2322888 蜀ICP备05006790号