{----------------------------------------------------------------------------------
 Description : attempts to exetute Command.com and pass it the CommandLine.
 Returns True if succeeds
 Parameters :
 sCommandLine : the command line to pass
 iCmdShow : desired starting visibility for the Command.com
 Wait : wait or not for the app to finish its job
 Error checking : NO
 Target : Delphi 2, 3, 4
 Example call : DOSCommand('C:\WINDOWS\NOTEPAD.EXE', SW_SHOW, True)
 DOSCommand('copy c:\*.bat c:\temp\*.bat', SW_HIDE, True);
 // path is illegal in the 2nd param of the ren DOS command
 DOSCommand('ren c:\temp\*.bat *.txt', SW_HIDE, True);
 DOSCommand('copy c:\*.bat c:\temp\*.bat > Out.txt', SW_HIDE, True);
 Author : Theodoros Bebekis, email bebekis@otenet.gr
-----------------------------------------------------------------------------------}
function DOSCommand(CommandLine : string; iCmdShow: integer; Wait: boolean): boolean;
var
 pComspec : array[0..255] of Char;
 pBoth : array[0..255] of Char;
 SI : TStartupInfo;
 PI : TProcessInformation;
begin
 Result := False;
 FillChar(SI, SizeOf(SI), #0);
 SI.cb := SizeOf(SI);
 SI.dwFlags := STARTF_USESHOWWINDOW; { need to set this in order to set wShowWindow }
 SI.wShowWindow := iCmdShow;
 { get the command.com position }
 GetEnvironmentVariable( 'COMSPEC', pComspec, SizeOf( pComspec));
 { DOS command such as copy or ren execution }
 FillChar(pBoth, SizeOf(pBoth), #0);
 StrCat(pBoth, pComspec);
 StrCat(pBoth, ' /C ');
 StrCat(pBoth, PChar(CommandLine));
 Result := CreateProcess( nil, pBoth, nil, nil, False, REALTIME_PRIORITY_CLASS	, nil, nil, SI, PI);
 if Result then
 begin
 if Wait then WaitforSingleObject(PI.hProcess, INFINITE);
 { close the handles }
 CloseHandle(PI.hProcess);
 CloseHandle(PI.hThread );
 end;
end;
-----------------------------------
Theo Bebekis
Thessaloniki, Greece
bebekis@otenet.gr
----------------------------------- 
> -----Original Message-----
> From: delphi-admin@elists.org [mailto:delphi-admin@elists.org]On Behalf Of Walter Ogston
> Sent: Wednesday, October 25, 2000 12:41 AM
> To: delphi@elists.org
> Subject: Copy files etc. 
> 
> 
> Hi Folks,
> 
> I am looking for a quick and easy (dirty?) way to copy the contents of a 
> directory to a new backup directory, possibly copy them back, then delete 
> the backup files and directory when done. If I were writing DOS scripts 
> they would look like this:
> 
> bkup.bat = {
> MD backdir
> copy *.* backdir /v
> }
> 
> rstor.bat = {
> DEL *.*
> COPY backdir *.* /v
> }
> 
> delbk.bat = {
> DEL backdir\*.*
> RD backdir
> }
> 
> Is there any way to execute batch files from inside a Delphi program, that 
> would do what I want. Or am I being naive in thinking this is the way to 
> do it?
> 
> TIA
> /*----------------
> C. Walter Ogston 		2717 Ridgeview Drive
> ogstoncw@worldnet.att.net		 Kalamazoo, Michigan 49008
> cwogston@cs.wmich.edu 		 (616) 349-1045
> */
> 
> 
> 
> _______________________________________________
> Delphi mailing list -> Delphi@elists.org
> http://elists.org/mailman/listinfo/delphi
> 
_______________________________________________
Delphi mailing list -> Delphi@elists.org
http://elists.org/mailman/listinfo/delphi