1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
|
//---------------------------------------------------------------------------
#include <vcl.h>
#include <stdio.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "cdiroutl"
#pragma resource "*.dfm"
TForm1 *Form1;
void DiskList(TStrings* Liste);
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
TreeView1->Items->Clear();
TTreeNode *Node;
TStrings *Liste;
Liste=new TStringList;
DiskList(Liste);
int i=0;
while(i<Liste->Count)
{
Node = TreeView1->Items->Add(NULL, Liste->Strings[i]);
AddChild(Node, Liste->Strings[i].c_str());
i++;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::TreeView1Expanding(TObject *Sender, TTreeNode *Node, bool &AllowExpansion)
{
AnsiString Path=Node->Text;
TTreeNode *Node2=Node->Parent;
TTreeNode *Node3;
while(Node2!=NULL)
{
Path=Node2->Text+"\\"+Path;
Node3=Node2;
Node2=Node3->Parent;
}
int i=0;
while(i<Node->Count)
{
AddChild(Node->Item[i], (Path+"\\"+Node->Item[i]->Text).c_str());
i++;
}
}
//---------------------------------------------------------------------------
void TForm1::AddChild(TTreeNode *Node1, char *NomDir)
{
WIN32_FIND_DATA FileData;
HANDLE hSearch;
char szNewPath[MAX_PATH];
sprintf(szNewPath, "%s\\*.*", NomDir) ;
hSearch = FindFirstFile(szNewPath, &FileData);
if (hSearch == INVALID_HANDLE_VALUE)
{
return;
}
do
{
if (((FileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY )
&& FileData.cFileName[0] != '.')
{
TreeView1->Items->AddChild(Node1, FileData.cFileName);
}
}while (FindNextFile(hSearch, &FileData));
FindClose(hSearch);
}
//---------------------------------------------------------------------------
void DiskList(TStrings* Liste)
{
int ch = 0;
char DriveSt[127];
GetLogicalDriveStrings(126, DriveSt);
while ( DriveSt[ch] != 0 )
{
Liste->Add(&DriveSt[ch]);
ch += strlen(&DriveSt[ch])+1;
}
}
//--------------------------------------------------------------------------- |
Partager