国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Java > 正文

瀏覽文件的一段代碼

2019-09-06 23:33:22
字體:
來源:轉載
供稿:網友

                    #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.SubString(1,1);
path=Drive+":";
currnode=TreeView1->Items->AddChild(TreeView1->Selected,DriveComboBox1->Items->Strings);
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->Text;
}
ListView1->Items->EndUpdate();
}
}
//---------------------------------------------------------------------------
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 介休市| 万山特区| 凌云县| 古浪县| 大洼县| 白水县| 上思县| 长乐市| 佛教| 宜兰市| 建阳市| 黔江区| 贺兰县| 临泉县| 昔阳县| 阿瓦提县| 彭州市| 金堂县| 宿州市| 永德县| 安阳县| 颍上县| 临夏县| 泌阳县| 孟连| 邵阳县| 贵州省| 翁源县| 治多县| 澳门| 广河县| 泽库县| 宁强县| 宜兰市| 韶山市| 集安市| 望城县| 哈巴河县| 象州县| 习水县| 绥德县|