//listed die drives
procedure List_Drives;
const
DRIVE_UNKNOWN = 0;
DRIVE_NO_ROOT_DIR = 1;
DRIVE_REMOVABLE = 2;
DRIVE_FIXED = 3;
DRIVE_REMOTE = 4;
DRIVE_CDROM = 5;
DRIVE_RAMDISK = 6;
var
r: LongWord;
Drives:
array[0..128]
of char;
pDrive: PChar;
begin
r := GetLogicalDriveStrings(SizeOf(Drives), Drives);
if r = 0
then Exit;
if r > SizeOf(Drives)
then
raise Exception.Create(SysErrorMessage(ERROR_OUTOFMEMORY));
pDrive := Drives;
while pDrive^ <> #0
do
begin
if GetDriveType(pDrive) = DRIVE_FIXED
then
Form1.ComboBox1.Items.Add(pDrive);
Inc(pDrive, 4);
end;
end;
//listed alles im tree-view
procedure GetDirectories(
Tree: TTreeView;
Directory:
string;
Item: TTreeNode;
IncludeFiles: Boolean
);
var
SearchRec: TSearchRec;
ItemTemp: TTreeNode;
begin
Directory := IncludeTrailingPathDelimiter(Directory);
if FindFirst(Directory + '
*.*', faDirectory
or faReadOnly
or faArchive, SearchRec) = 0
then
begin
repeat
if Pos(SearchRec.
Name, '
..') = 1
then
Continue
else
if (SearchRec.Attr
and faDirectory = faDirectory)
then
GetDirectories(
Tree,
Directory + SearchRec.
Name,
Tree.Items.AddChildObject(Item, SearchRec.
Name, Pointer(1)),
IncludeFiles
)
else
if IncludeFiles
then
Tree.Items.AddChild(Item, SearchRec.
Name);
until FindNext(SearchRec) <> 0;
FindClose(SearchRec);
end;
end;
function TreeNodePath(node: TTreeNode; delimiter: Char = PathDelim):
string;
begin
if Assigned(node)
then Result := TreeNodePath(node.Parent, delimiter) + delimiter + node.Text
else Result := '
';
end;
//zeigt die tree-list view an
procedure TForm1.TreeView1Change(Sender: TObject; Node: TTreeNode);
begin
Caption := TreeNodePath(Node);
//akt. makiertes element im treeview
driveletter := combobox1.Text;
//combobox zum string
delete(driveletter, length(driveletter),2);
//string kuerzen
label1.caption := driveletter+TreeNodePath(Node);
//letter+path
end;
procedure TForm1.Button1Click(Sender: TObject);
var
Node: TTreeNode;
Path:
string;
Dir:
string;
begin
Dir := combobox1.text;
Screen.Cursor := crHourGlass;
TreeView1.Items.BeginUpdate;
try
TreeView1.Items.Clear;
GetDirectories(TreeView1, Dir,
nil, True);
finally
Screen.Cursor := crDefault;
TreeView1.Items.EndUpdate;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
List_Drives;
//refresh fuer die drives
end;