Board index » delphi » msdos commands

msdos commands

how to i incorperate an msdos command into a pascal program? i was wantint
to copy a file to a floppy disk, before i opened it, just incase the program
cr4ashed, and the file was lost completly.

thank you for your help

craig hennessey
cr...@hennessey.club24.co.uk
http://www.geocities.com/craighennessey17/index2.html

 

Re:msdos commands


In article <977338184.972...@news.tibus.net>,

Quote
Craig Hennessey <cr...@hennessey.club24.co.uk> wrote:
>how to i incorperate an msdos command into a pascal program? i was wantint
>to copy a file to a floppy disk, before i opened it, just incase the program
>cr4ashed, and the file was lost completly.

You could use exec(getenv('comspec'),'/c '+command);

Remember swapvectors and limiting the heap. However, it is better to do
the copying yourself with blockread and blockwrite in a loop.

Osmo

Re:msdos commands


If you copy the file yourself using -blockread/write- (which *is* the
better solution), make sure you preserve the file date/time [for
completeness' sake] (i.e., grab the file date/time of the original file
and set the newly-copied file to the same).

Kingpin.

Quote
Osmo Ronkanen wrote:

> In article <977338184.972...@news.tibus.net>,
> Craig Hennessey <cr...@hennessey.club24.co.uk> wrote:
> >how to i incorperate an msdos command into a pascal program? i was wantint
> >to copy a file to a floppy disk, before i opened it, just incase the program
> >cr4ashed, and the file was lost completly.

> You could use exec(getenv('comspec'),'/c '+command);

> Remember swapvectors and limiting the heap. However, it is better to do
> the copying yourself with blockread and blockwrite in a loop.

> Osmo

Re:msdos commands


Quote
In article <3A41184D.2...@datastar.com>, Kingpin  <nwar...@datastar.com> wrote:
>If you copy the file yourself using -blockread/write- (which *is* the
>better solution), make sure you preserve the file date/time [for
>completeness' sake] (i.e., grab the file date/time of the original file
>and set the newly-copied file to the same).

The following should copy a file from n1 to n2. You need to supply it a
temporary buffer as well as the length of the buffer. It returns status
in error. There is no checking against overwriting existing files. The
buffer should be at least a few kilobytes.

for example:

var buffer:array[1..8192] of byte;
    error:word;
    filename1,filename2:string;

Copyfile(Filename1,Filename2,buffer,sizeof(buffer),error);
if error>0 then Writeln('Error ',error,' while copying');
...

You can also allocate the buffer from the heap. It is completely up to
the caller where it gets the buffer just that it provides correct buffer
and size to the copy routine.

You could try mem[$b800:0],4000 to get funny effects :-)

Procedure CopyFile(const n1,n2:String; var buff; buffsize:word
                   var error:word);
var f1,f2:file;
    bytesread:word;
    f:word;
Begin
  {$i-}
  Assign(f1,n1);
  Assign(f2,n2);
  reset(f1,1);
  rewrite(f2,1);

  repeat
    BlockRead(f1,buff,buffsize,bytesread);
    BlockWrite(f2,buff,bytesread);
  until (bytesread=0) or (inoutres>0);
  GetFtime(f1,t);
  SetFtime(f2,t);
  Close(f1);
  Close(f2);

  Error:=ioresult;
  {$i+}
End;

If you have pre TP 7.0 remove the const from the header.

Osmo

Other Threads