Board index » delphi » Executing a BAT file

Executing a BAT file

Hi
        Since I couldnt find any function to copy a file under Delphi is
there any way to run a .bat file under delphi?
        Is there any way to know the curret Windows directory?

 Thank you very much, Andre Brandao, CT2GGD

        *****************************************
        *                                       *
        *  Andre Brandao                        *
        *  E-mail: l42...@alfa.ist.utl.pt       *
        *      or  ac...@camoes.rnl.ist.utl.pt  *
        *                                       *
        *****************************************

 

Re:Executing a BAT file


Quote
Andre Brandao wrote:

> Hi
>         Since I couldnt find any function to copy a file under Delphi is
> there any way to run a .bat file under delphi?
>         Is there any way to know the curret Windows directory?

>  Thank you very much, Andre Brandao, CT2GGD

>         *****************************************
>         *                                       *
>         *  Andre Brandao                        *
>         *  E-mail: l42...@alfa.ist.utl.pt       *
>         *      or  ac...@camoes.rnl.ist.utl.pt  *
>         *                                       *
>         *****************************************

You can try calling winexec.
But I would code a small copy routine into my code.

regards

Re:Executing a BAT file


Use the WinExec function (or CreateProcess).

-Paul

Re:Executing a BAT file


Andre,
    There is a sample of some code for copying files in the FMXUtils unit
of the demo in Delphi's
\Demos\Docs\Filmanex directory. Just copy the CopyFile and HasAttr
functions from this unit into
your unit and add Consts and ShellAPI to your uses clause.  This has worked
fine for me.

Hope this helps!
--
Rod Geraghty (:>)
GERA-Tech
Ottawa, Canada
gera...@ibm.net

Andre Brandao <l42...@alfa.ist.utl.pt> wrote in article
<Pine.OSF.3.91.970225173021.5558A-100...@alfa.ist.utl.pt>...

Quote
> Hi
>    Since I couldnt find any function to copy a file under Delphi is
> there any way to run a .bat file under delphi?
>    Is there any way to know the curret Windows directory?

>  Thank you very much, Andre Brandao, CT2GGD

>         *****************************************
>         *                                       *
>         *  Andre Brandao                        *
>         *  E-mail: l42...@alfa.ist.utl.pt       *
>         *      or  ac...@camoes.rnl.ist.utl.pt  *
>         *                                       *
>         *****************************************

Re:Executing a BAT file


Andre,
  BTW, WRT my previous email, I originally got this info by looking up
CopyFile in the D1 and D2 User's Guides.

As for you second question try something like this:

var
  WD, SD: PChar;
  WinDir, SysDir: String;

begin
    {Get path for Windows directory.}
  WD := StrAlloc(200);
  GetWindowsDirectory(WD, 200);
  WinDir := StrPas(WD);
  StrDispose(WD);
    {Check to see if windows dir is root directory and take '\' off the
    end of WinDir if it is.  This is part of the GetWindowsDirectory
function
    which only puts a '\' at the end of the Windows directory path if it is
    also the root directory.  This should not normally be the case but this
    will prevent an error later if it is.}
  if WinDir[Length(WinDir)] = '\' then
    Delete(WinDir, Length(WinDir), 1);
    {Get path for System directory.}
  SD := StrAlloc(200);
  GetSystemDirectory(SD, 200);
  SysDir := StrPas(SD);
  StrDispose(SD);
    {Check to see if system dir is root directory and take '\' off the
    end of SysDir if it is.  This is part of the GetSystemDirectory
function
    which only puts a '\' at the end of the Windows directory path if it is
    also the root directory.  This should not normally be the case but this
    will prevent an error later if it is.}
  if SysDir[Length(SysDir)] = '\' then
    Delete(SysDir, Length(SysDir), 1);
end;

Hope this helps!
--
Rod Geraghty (:>)
GERA-Tech
Ottawa, Canada
gera...@ibm.net

Rodney E Geraghty <gera...@ibm.net> wrote in article
<01bc2436$c515b7a0$45a92581@default>...

Quote
> Andre,
>     There is a sample of some code for copying files in the FMXUtils unit
> of the demo in Delphi's
> \Demos\Docs\Filmanex directory. Just copy the CopyFile and HasAttr
> functions from this unit into
> your unit and add Consts and ShellAPI to your uses clause.  This has
worked
> fine for me.

> Hope this helps!
> --
> Rod Geraghty (:>)
> GERA-Tech
> Ottawa, Canada
> gera...@ibm.net

Re:Executing a BAT file


Quote
Philip Stuyck wrote:

> Andre Brandao wrote:

> > Hi
> >         Since I couldnt find any function to copy a file under Delphi is
> > there any way to run a .bat file under delphi?
> >         Is there any way to know the curret Windows directory?

> >  Thank you very much, Andre Brandao, CT2GGD

> >         *****************************************
> >         *                                       *
> >         *  Andre Brandao                        *
> >         *  E-mail: l42...@alfa.ist.utl.pt       *
> >         *      or  ac...@camoes.rnl.ist.utl.pt  *
> >         *                                       *
> >         *****************************************
> You can try calling winexec.
> But I would code a small copy routine into my code.

> regards

It is far easier to use the WINAPI call CopyFile, prototyped
as follows in D2 (actually, here is the whole family):

function CopyFileA(lpExistingFileName, lpNewFileName: PAnsiChar;
bFailIfExists: BOOL): BOOL; stdcall;
function CopyFileW(lpExistingFileName, lpNewFileName: PWideChar;
bFailIfExists: BOOL): BOOL; stdcall;
function CopyFile(lpExistingFileName, lpNewFileName: PChar;
bFailIfExists: BOOL): BOOL; stdcall;

If you need more info, search the Win32 APi Help for more info on
parameters/usage.

--
John Matasovsky
e-mail:  john.matasov...@bigfoot.com
Views expressed here are purely my own and in no way reflect
those of my employer.

Re:Executing a BAT file


Hello Andre!

Tuesday February 25 1997, Andre Brandao wrote to All:

 AB>   Since I couldnt find any function to copy a file under Delphi is
 AB> there any way to run a .bat file under delphi?
 AB>   Is there any way to know the curret Windows directory?

Getwindowsdirectory should do the trick.

Kind regards Ole

    E-Mail: Ole_Morten...@Hotmail.com

Other Threads