McMint wrote:At present I am writing an application in HMG to copy files from one location to another on our network.
...
This works fine if the file is not in use. I use the ferase() function to remove the old file and to determine if I can copy or not. If the file is in use then it cannot be erased and so the copy would be flagged as failed.
If I remove the ferase() call and try and run it I get a DOS error 32 - Sharing Violation if the file is in use.
I seem to remember from my clipper days a function called FCOPY() that was in some of the TP Libraries. It would overwrite the file, even if it was open. Does anyone know of an equivalent function(s) in Harbour/HMG that I could use to do the copy? I have been unable to track one down in the documentation.
Could I use FCREATE()/FREAD()/FCLOSE() etc?
Any suggestions/assistance will be much appreciated.
Thanks.
Regards
McMint.
(An Englishman living in Scotland - and loving it!
)
Hello McMint, you are welcome
IMHO there isn't any command / function that overwrite an open file. This is no Harbour but a file system issue. Do you like anyone will erase / fully change a file while your are using it ?
If your goal is avoiding run time errors, IMHO you have make like this :
- First check the file is in use: if your file is a .dbf, USE'ing exclusively or better try FOPEN() function by exclusive option.
e.g. FOPEN( <cfile>, 16 )
Return value of FOPEN() < 0 ( -1 ) indicate an error. If this value is > zero, you can erase or overwrite it. ( Don't forget FCLOSE() before attempt this. )
IMHO better way may be:
- Since this is a network environment, all common ( everyone will use ) files must open sharing mode. And shared files will never erase nor overwrite. Also can't be ZAP'ped, PACK'ed etc. If an inevitable situation occurs, before send a message to all users such as "We have a system maintenance process; please interrupt your work for a little time.."
- If possible, try update for changes the file instead of fully replace it.
BTW, no FCOPY() but we have FILECOPY() function.
Code: Select all
SYNTAX :
FILECOPY(<cSourceFile>, <cTargetFile>, [<lMode>]) --> nCopyByte
ARGUMENTS :
<cSourceFile> Designates the source file. Drive and path designations are permitted, but not wildcards.
<cTargetFile> Designates the target file. Drive and path designations are permitted, but not wildcards.
<lMode> Designates the backup mode on when designated as .T. The default is no backup mode (.F.).
I hope that this infos will be useful for you.
Regards
--
esgici