TRG00
asked on
Executing Tree DOS function in Delphi?
Hi, want to display or save the DOS tree function of a particular directory depending on the RadioButton. It only works some times, if I click the button twice..five times, tried putting Application.ProcessMessage s into the code but did not work.
Sorry for all the code, but maybe it could help.
Thanks
TRG00
CODE:
procedure TForm1.SpeedButton6Click(S ender: TObject);
var sSaveDir, sTreeDir, sTreeCommand, sTreeDisplay, sDisAllFile :String;
TextF, TextF2, TextFCreate : TextFile;
begin
if CheckBox1.Checked = true then sDisAllFile := '/f'
else sDisAllFile := '';
sTreeDir := stvSelectDir.Path;
AssignFile(TextF2, 'TreeCom.bat');
{$I-} Rewrite(TextF2); {$I+}
if IOResult <> 0 then ShowMessage('Error in saving the file!');
if RadioButton4.Checked = true then
begin
SaveDialog1.Execute;
sSaveDir := SaveDialog1.FileName;
AssignFile(TextFCreate, sSaveDir);
{$I-} Rewrite(TextFCreate); {$I+}
if IOResult <> 0 then ShowMessage('Error in saving the file!');
CloseFile(TextFCreate);
sTreeCommand := 'tree.com ' +ExtractShortPathName(sTre eDir) +' /a'+sDisAllFile +' >> '+ExtractShortPathName(sSa veDir);
lblDis.caption := sTreeCommand;
Write(TextF2,sTreeCommand) ;
closeFile(TextF2);
ShellExecute(0, 'open', 'TreeCom.bat', '', '', SW_HIDE);
Application.ProcessMessage s;
end;
if RadioButton3.Checked = true then
begin
lstTree.clear;
sTreeCommand := 'tree.com ' +ExtractShortPathName(sTre eDir) +' /a'+sDisAllFile +' >> ' + 'Tree.txt';
Write(TextF2,sTreeCommand) ;
closeFile(TextF2);
Application.ProcessMessage s;
ShellExecute(0, 'open', 'TreeCom.bat', '', '', SW_HIDE);
AssignFile(TextF, 'Tree.txt');
{$I-} Reset(TextF); {$I+}
if IOResult <> 0 then ShowMessage('Error creating the file!');
while not eof(TextF) do
begin
Readln(TextF, sTreeDisplay);
lstTree.Items.Add(sTreeDis play);
end;
closefile(TextF);
DeleteFile('Tree.txt');
end;
end;
Sorry for all the code, but maybe it could help.
Thanks
TRG00
CODE:
procedure TForm1.SpeedButton6Click(S
var sSaveDir, sTreeDir, sTreeCommand, sTreeDisplay, sDisAllFile :String;
TextF, TextF2, TextFCreate : TextFile;
begin
if CheckBox1.Checked = true then sDisAllFile := '/f'
else sDisAllFile := '';
sTreeDir := stvSelectDir.Path;
AssignFile(TextF2, 'TreeCom.bat');
{$I-} Rewrite(TextF2); {$I+}
if IOResult <> 0 then ShowMessage('Error in saving the file!');
if RadioButton4.Checked = true then
begin
SaveDialog1.Execute;
sSaveDir := SaveDialog1.FileName;
AssignFile(TextFCreate, sSaveDir);
{$I-} Rewrite(TextFCreate); {$I+}
if IOResult <> 0 then ShowMessage('Error in saving the file!');
CloseFile(TextFCreate);
sTreeCommand := 'tree.com ' +ExtractShortPathName(sTre
lblDis.caption := sTreeCommand;
Write(TextF2,sTreeCommand)
closeFile(TextF2);
ShellExecute(0, 'open', 'TreeCom.bat', '', '', SW_HIDE);
Application.ProcessMessage
end;
if RadioButton3.Checked = true then
begin
lstTree.clear;
sTreeCommand := 'tree.com ' +ExtractShortPathName(sTre
Write(TextF2,sTreeCommand)
closeFile(TextF2);
Application.ProcessMessage
ShellExecute(0, 'open', 'TreeCom.bat', '', '', SW_HIDE);
AssignFile(TextF, 'Tree.txt');
{$I-} Reset(TextF); {$I+}
if IOResult <> 0 then ShowMessage('Error creating the file!');
while not eof(TextF) do
begin
Readln(TextF, sTreeDisplay);
lstTree.Items.Add(sTreeDis
end;
closefile(TextF);
DeleteFile('Tree.txt');
end;
end;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I tried EddieShipman solution, and it is working thanks.
JDuncan thanks for your solution, is shorter but EddieShipman was just faster. :-(
CIA thanks again
JDuncan thanks for your solution, is shorter but EddieShipman was just faster. :-(
CIA thanks again
try using createprocess which can wait as follows :-
global variables
MyHandle : THandle;
si : _STARTUPINFOA;
pi :_PROCESS_INFORMATION;
CreateProcess(pchar('Treec
MyHandle:=pi.hProcess;
WaitForSingleObject(MyHand
100000 is a timeout to wait for in milliseconds, I think there is avalue to set it to infinite if necessary.