Hi Weez,
We need to add another component to let you do that easily. Create an instance of TDirectoryOutline which is in the Samples palette.
The following code will give you everything that Explorer sees:
procedure BuildTree;
var DirName,FilName:string;
Loop,PrevIC,FLoop:integer;
begin
XDirectoryOutline1.Directory:='c:\';
{ TDirectoryOutline appears to have a bug in its
implementation of FullExpand so the following
REPEAT loop does the full expand instead}
repeat
PrevIC:=XDirectoryOutline1.ItemCount;
for Loop:=1 to XDirectoryOutline1.ItemCount do
XDirectoryOutline1.Items[Loop].Expand;
until XDirectoryOutline1.ItemCount=PrevIC;
//we now have all the directory names
for Loop:=1 to XDirectoryOutline1.ItemCount do
begin
{FullPath returns the directory name with '\\'
after the drive letter, so we need to remove the
extra '\'}
dirname:=XDirectoryOutline1.Items[Loop].FullPath;
dirname:=copy(dirname,1,3)+copy(dirname,5,255);
{set the DirectoryListBox directory}
DirectoryListBox1.Directory:=dirname;
{we now have all files for that directory}
for FLoop:=1 to FileListBox1.Items.Count do
if UpperCase(DirName)='C:\' then
FilName:=dirname+FileListBox1.Items[FLoop-1]
else
FilName:=dirname+'\'+FileListBox1.Items[FLoop-1];
{do what ever you want with the file name}
end;
end;
Roger Fedyk