Board index » delphi » Using DOS 'move' command through TP7

Using DOS 'move' command through TP7

I'm writing a program in TP7 that reads a file name and directory name
from a text file and
then moves the file to the read directory using the 'Exec' command.
But
I get DOS error #5
(Access Denied). I've tried running the exact coomand from a batch
file
and it works
perfectly. I'm running TP7 from Windows '95 because I'm going to use
my
program through
Windows. The command is:
  move "C:\Program Files\Ctl3d.dll" "C:\Program Files\Temp"

My command in Pascal is:
  {$M $4000,0,0 }
  SwapVectors;
  Exec ('', 'move "C:\Program Files\Ctl3d.dll" "C:\Program
Files\Temp"')
  SwapVectors;
  IF (DosError <> 0) THEN WriteLn ('DOS error #', DosError);

What's going on??? (I need this desperately)

 

Re:Using DOS 'move' command through TP7


Quote
In article <4ppudj$...@igubu.saix.net> posenj.lan...@elab.co.za (Kevin Posen) writes:
>I'm writing a program in TP7 that reads a file name and directory name
>from a text file and
>then moves the file to the read directory using the 'Exec' command.
>But
>I get DOS error #5
>(Access Denied). I've tried running the exact coomand from a batch
>file
>and it works
>perfectly. I'm running TP7 from Windows '95 because I'm going to use
>my
>program through
>Windows. The command is:
>  move "C:\Program Files\Ctl3d.dll" "C:\Program Files\Temp"
>My command in Pascal is:
>  {$M $4000,0,0 }
>  SwapVectors;
>  Exec ('', 'move "C:\Program Files\Ctl3d.dll" "C:\Program Files\Temp"')
>  SwapVectors;
>  IF (DosError <> 0) THEN WriteLn ('DOS error #', DosError);

exec requires two parameters, Path and CmdLine, where Path is the program to
run (in this case, move), and CmdLine is the command tail that would follow
the command.

Try modifying your call to exec() as:

  exec ('move','"C:\Program Files\Ctl3d.dll" "C:\Program Files\Temp"');

and that ought to fix your problem.

Quote
>What's going on??? (I need this desperately)

--
Scott Earnest          | We now return you to our regularly scheduled |
siny...@{*word*104}space.org | chaos and mayhem. . . .                      |

Re:Using DOS 'move' command through TP7


Quote
siny...@{*word*104}space.org (Scott Earnest) wrote:
> In article <4ppudj$...@igubu.saix.net> posenj.lan...@elab.co.za (Kevin Posen) writes:

> >I'm writing a program in TP7 that reads a file name and directory name
> >from a text file and
> >then moves the file to the read directory using the 'Exec' command.
> >But I get DOS error #5 (Access Denied).

[snip]

Quote
> >My command in Pascal is:
> >  {$M $4000,0,0 }
> >  SwapVectors;
> >  Exec ('', 'move "C:\Program Files\Ctl3d.dll" "C:\Program Files\Temp"')
> >  SwapVectors;
> >  IF (DosError <> 0) THEN WriteLn ('DOS error #', DosError);

> exec requires two parameters, Path and CmdLine, where Path is the program to
> run (in this case, move), and CmdLine is the command tail that would follow
> the command.

> Try modifying your call to exec() as:

>   exec ('move','"C:\Program Files\Ctl3d.dll" "C:\Program Files\Temp"');

> and that ought to fix your problem.

This is right, but you'll need the full path name & extension for the move command:

exec ('C:\Win95\Command\move.exe','"C:\Program Files\Ctl3d.dll" "C:\Program Files\Temp"');

Ron Muzzi, EE
Great Lakes Environmental Research Lab
Ann Arbor, Michigan, USA
mu...@glerl.noaa.gov

Re:Using DOS 'move' command through TP7


Quote
In article <4pruv4$...@hovis.rdc.noaa.gov> Ron Muzzi <mu...@glerl.noaa.gov> writes:
>siny...@{*word*104}space.org (Scott Earnest) wrote:
>> [...]

>> Try modifying your call to exec() as:

>>   exec ('move','"C:\Program Files\Ctl3d.dll" "C:\Program Files\Temp"');

>> and that ought to fix your problem.
>This is right, but you'll need the full path name & extension for the move
>command:
>exec ('C:\Win95\Command\move.exe','"C:\Program Files\Ctl3d.dll" "C:\Program
>Files\Temp"');

Actually, you should really take this one step further:

var
  cmd : pathstr;

begin
  cmd := fsearch('move.exe',getenv('PATH'));
  swapvectors;
  exec (cmd,'"C:\Program Files\Ctl3d.dll" "C:\Program Files\Temp"');
  swapvectors;
  {evaluate DOSError to check if successful}
end;

It's usually not a good idea to hard-code a directory as such, especially if
the program could be run on different machines with different
configurations.  Likewise, it may not be a good idea to hard-code the paths
you're passing to the move program.

Quote
>Ron Muzzi, EE
>Great Lakes Environmental Research Lab
>Ann Arbor, Michigan, USA
>mu...@glerl.noaa.gov

--
Scott Earnest          | We now return you to our regularly scheduled |
siny...@{*word*104}space.org | chaos and mayhem. . . .                      |

Re:Using DOS 'move' command through TP7


In article <sinykal.397.00002...@{*word*104}space.org>,

Quote
Scott Earnest <siny...@{*word*104}space.org> wrote:
>In article <4ppudj$...@igubu.saix.net> posenj.lan...@elab.co.za (Kevin Posen) writes:

>>I'm writing a program in TP7 that reads a file name and directory name
>>from a text file and
>>then moves the file to the read directory using the 'Exec' command.
>>But
>>I get DOS error #5
>>(Access Denied). I've tried running the exact coomand from a batch
>>file
>>and it works
>>perfectly. I'm running TP7 from Windows '95 because I'm going to use
>>my
>>program through
>>Windows. The command is:
>>  move "C:\Program Files\Ctl3d.dll" "C:\Program Files\Temp"

>>My command in Pascal is:
>>  {$M $4000,0,0 }
>>  SwapVectors;
>>  Exec ('', 'move "C:\Program Files\Ctl3d.dll" "C:\Program Files\Temp"')
>>  SwapVectors;
>>  IF (DosError <> 0) THEN WriteLn ('DOS error #', DosError);

>exec requires two parameters, Path and CmdLine, where Path is the program to
>run (in this case, move), and CmdLine is the command tail that would follow
>the command.

>Try modifying your call to exec() as:

>  exec ('move','"C:\Program Files\Ctl3d.dll" "C:\Program Files\Temp"');

>and that ought to fix your problem.

Wrong! Try exec(getenv('comspec'),'/c move ...');

The exec does not search the path. It also requires a complete program
name.

Osmo

Re:Using DOS 'move' command through TP7


Quote
In article <4q0gjs$...@kruuna.helsinki.fi> ronka...@cc.helsinki.fi (Osmo Ronkanen) writes:
>>Try modifying your call to exec() as:

>>  exec ('move','"C:\Program Files\Ctl3d.dll" "C:\Program Files\Temp"');

>>and that ought to fix your problem.

>Wrong! Try exec(getenv('comspec'),'/c move ...');
>The exec does not search the path. It also requires a complete program
>name.

Yes, that was already corrected -- twice, once by another reader and again
by myself to add an even better method of getting the full command for move
using the fsearch() function.

And the corrected method is more efficient in that in runs only one program
(move.exe) instead of two (command.com and move.exe).  Calling command.com
is really only necessary if the output of the call is going to be redirected
using ">", ">>", "<", "|", or the other redirection declarators used by
shells such as 4DOS/NDOS.

Quote
>Osmo

--
Scott Earnest          | We now return you to our regularly scheduled |
siny...@{*word*104}space.org | chaos and mayhem. . . .                      |

Re:Using DOS 'move' command through TP7


Quote
Kevin Posen (posenj.lan...@elab.co.za) wrote:

: I'm writing a program in TP7 that reads a file name and directory name
: from a text file and then moves the file to the read directory
: using the 'Exec' command.

: Exec ('', 'move "C:\Program Files\Ctl3d.dll" "C:\Program

Funny that so far nobody noticed the easiest solution:

var f : file;

assign (f,filename1);
rename (f,filename2);

This works! Even accross directories!! However not across
drives, but this was not required in the example above.
Plus you don't need DOS 5, this works fine with Dos 3.3.
The move procedure has been in DOS for a long time
before the people responsible for command.com found it
and invented the move command to access it.

If you need to cross drive boundaries, then you can use
   exec (getenv('COMSPEC'),'move '+filename1 + filename2);

Klaus
--
Klaus Hartnegg, Institut fuer Biophysik, Hansa-Strasse 9a, D-79104 Freiburg
hartn...@uni-freiburg.de   http://www.brain.uni-freiburg.de/~klaus/

Re:Using DOS 'move' command through TP7


In article <sinykal.417.00179...@{*word*104}space.org>,

Quote
Scott Earnest <siny...@{*word*104}space.org> wrote:
>In article <4q0gjs$...@kruuna.helsinki.fi> ronka...@cc.helsinki.fi (Osmo Ronkanen) writes:

>>>Try modifying your call to exec() as:

>>>  exec ('move','"C:\Program Files\Ctl3d.dll" "C:\Program Files\Temp"');

>>>and that ought to fix your problem.

>>Wrong! Try exec(getenv('comspec'),'/c move ...');

>>The exec does not search the path. It also requires a complete program
>>name.

>Yes, that was already corrected -- twice, once by another reader and again
>by myself to add an even better method of getting the full command for move
>using the fsearch() function.

If you are not a newbie you'd know that news articles can take days in
traveling across the atlantic. I was giving the simplest solution. It
also exactly like what happens at command line. Nor just something like
it. (For example if there was a move.bat, that called move.exe, by
version would execute it)

Of course if done properly moving files does not involve exec at all.

Osmo

Re:Using DOS 'move' command through TP7


In article <4q3ssi$...@n.ruf.uni-freiburg.de> hartn...@sun2.ruf.uni-freiburg.de (Klaus Hartnegg) writes:

Quote
>Kevin Posen (posenj.lan...@elab.co.za) wrote:
>: I'm writing a program in TP7 that reads a file name and directory name
>: from a text file and then moves the file to the read directory
>: using the 'Exec' command.
>: Exec ('', 'move "C:\Program Files\Ctl3d.dll" "C:\Program
>Funny that so far nobody noticed the easiest solution:
>var f : file;
>assign (f,filename1);
>rename (f,filename2);
>This works! Even accross directories!! However not across
>drives, but this was not required in the example above.
>Plus you don't need DOS 5, this works fine with Dos 3.3.
>The move procedure has been in DOS for a long time
>before the people responsible for command.com found it
>and invented the move command to access it.

To an extent, yes, but there are some things to consider:

1.)  Does it work across drives?  No (as you mention).  Though the example
     doesn't show that reading across drives is necessary, Kevin does say
     that the source will read the names from a text file as needed.  This
     suggestion could be a real weakness if it happens that the text file
     contains names on different volumes.

2.)  Does it work in Win95/DOS 7?  Nope, the standard calls don't know what
     to do with long file names -- either an intermediate handler like
     move.exe must be used, or it requires a unit to handle long file names.

So while it might be something that could work in a pinch, it may well not
get the job it's intended to do done.

Quote
>If you need to cross drive boundaries, then you can use
>   exec (getenv('COMSPEC'),'move '+filename1 + filename2);

I think every problem with this line of code has been pointed out in the
other articles in this thread.  I won't rehash the corrections and better
solutions.

Quote
>Klaus
>--
>Klaus Hartnegg, Institut fuer Biophysik, Hansa-Strasse 9a, D-79104 Freiburg
>hartn...@uni-freiburg.de   http://www.brain.uni-freiburg.de/~klaus/

--
Scott Earnest          | We now return you to our regularly scheduled |
siny...@{*word*104}space.org | chaos and mayhem. . . .                      |

Re:Using DOS 'move' command through TP7


Quote
siny...@{*word*104}space.org (Scott Earnest) wrote:
>In article <4pruv4$...@hovis.rdc.noaa.gov> Ron Muzzi <mu...@glerl.noaa.gov> writes:
>>siny...@{*word*104}space.org (Scott Earnest) wrote:
>>> [...]

>>> Try modifying your call to exec() as:

>>>   exec ('move','"C:\Program Files\Ctl3d.dll" "C:\Program Files\Temp"');

>>> and that ought to fix your problem.
>>This is right, but you'll need the full path name & extension for the move
>>command:
>>exec ('C:\Win95\Command\move.exe','"C:\Program Files\Ctl3d.dll" "C:\Program
>>Files\Temp"');
>Actually, you should really take this one step further:
>var
>  cmd : pathstr;
>begin
>  cmd := fsearch('move.exe',getenv('PATH'));
>  swapvectors;
>  exec (cmd,'"C:\Program Files\Ctl3d.dll" "C:\Program Files\Temp"');
>  swapvectors;
>  {evaluate DOSError to check if successful}
>end;
>It's usually not a good idea to hard-code a directory as such, especially if
>the program could be run on different machines with different
>configurations.  Likewise, it may not be a good idea to hard-code the paths
>you're passing to the move program.
>>Ron Muzzi, EE
>>Great Lakes Environmental Research Lab
>>Ann Arbor, Michigan, USA
>>mu...@glerl.noaa.gov
>--
>Scott Earnest          | We now return you to our regularly scheduled |
>siny...@{*word*104}space.org | chaos and mayhem. . . .                      |

Thanks but I found the answer:
   Exec(GetEnv('COMSPEC'),'/C "C:\Program Files\Ctl3d.dll" "C:\Program
Files\temp"')

Other Threads