|
Copying files - Traping file sharing error
Author |
Message |
Andrew Williamso #1 / 5
|
Copying files - Traping file sharing error
I am using Borland Pascal v7.01 I am copying files from one directory to another directory using the exec procedure shown below. exec(getenv('COMSPEC'),'/C COPY '+FromFile+' '+ToFile+' >NUL'); This works fine until one of the "FromFiles" is still open and causes a file sharing conflict. All I want to do is prevent the file sharing conflict from being displayed, I already know that the file has not been copied because I check the To directory to see if the copied file exists. I have the following memory allocation parameters at the start of my program {$M $8000,0,$4000 } If I remove them all the file sharing conflict is not displayed, but a lot more of the files fail with error 10 - "The environment is incorrect" Any suggestions would be appreciated. Thank you Andrew.
|
Tue, 05 Aug 2003 17:14:22 GMT |
|
|
Osmo Ronkan #2 / 5
|
Copying files - Traping file sharing error
Quote:
>I am using Borland Pascal v7.01 >I am copying files from one directory to another directory using the >exec procedure shown below. > exec(getenv('COMSPEC'),'/C COPY '+FromFile+' '+ToFile+' >NUL');
Don't. Instead write the copy routine as part of yuor code:' var fp1,fp2:file; buffer:array[1..4096] of byte; {$i-} assign(fp1,fromfile); Assign(fp2,Tofile); reset(fp2,1); rewrite(fp1,1) Repeat Blockread(fp1,buffer,sizeof(buffer),bytesread); Blockwrite(fp2,buffer,bytesread); until (bytesread=0) or (inoutres<>0); close(fp1); close(fp2); if ioresult<>0 then...
|
Tue, 05 Aug 2003 19:31:24 GMT |
|
|
Andrew Williamso #3 / 5
|
Copying files - Traping file sharing error
Thankyou.. I didn't really want to do it that way as it changes the date and time, but it looks like I am going to have to. I can always reset the date and time if the copy process has no errors. I just thought there was a quick fix to prevent the error from being displayed.
|
Tue, 05 Aug 2003 19:41:32 GMT |
|
|
Osmo Ronkan #4 / 5
|
Copying files - Traping file sharing error
Quote:
>Thankyou.. >I didn't really want to do it that way as it changes the date and time, >but it looks like I am going to have to. I can always reset the date >and time if the copy process has no errors.
You just need GetFtime(fp1,t); setftime(fp2,t); where t is a longint. The files need to be open. Quote: >I just thought there was a quick fix to prevent the error from being >displayed.
Well you'd need to redirect standard error. Command.com does not uspport it. You should be able to do that from Pascal but I do not knwo eactly how. Osmo
|
Wed, 06 Aug 2003 00:04:24 GMT |
|
|
Frank Peel #5 / 5
|
Copying files - Traping file sharing error
Quote:
> >Thankyou.. > >I didn't really want to do it that way as it changes the date and time, > >but it looks like I am going to have to. I can always reset the date > >and time if the copy process has no errors. > You just need GetFtime(fp1,t); setftime(fp2,t); where t is a longint. > The files need to be open. > >I just thought there was a quick fix to prevent the error from being > >displayed. > Well you'd need to redirect standard error. Command.com does not uspport > it. You should be able to do that from Pascal but I do not knwo eactly > how.
I doubt it could be done from Pascal, but you can do anything with BASM. Standard handles are: 0 - STDIN, 1 - STDOUT, 2 - STDERR, 3 - STDAUX, 4 - STDPRN. IIRC, to redirect one of these, I closed it and then opened the file to redirect it to. So from inline assembler, you might - back up handle 2 by making a duplicate with int 21h fn 45h - close it with int 21h fn 3Eh - open a file with int 21h fn 3Dh. The new file would get that handle because it's the first one free. If the redirect file was already open, use int 21h fn. 46h to do the redirection. - run your child process. - close handle 2 - use int 21h fn 46h to redirect handle 2 back to what it should be, ie copy the backup handle. - close your backup handle with int 21h fn 3Eh. FP
|
Wed, 06 Aug 2003 02:06:27 GMT |
|
|
|