File Copy Routines - aka FCOPY()

HMG Samples and Enhancements

Moderator: Rathinagiri

Post Reply
McMint
Posts: 2
Joined: Wed Nov 19, 2008 3:57 pm

File Copy Routines - aka FCOPY()

Post by McMint » Wed Nov 19, 2008 4:33 pm

At present I am writing am application in HMG to copy files from one location to another on our network. The actual copy section is

Code: Select all

static function DoCopy(cName,cOut,lSuccess)
    // set lSuccess to failed 
    lSuccess:=.f.

    if (ferase((cOut)) == 0)
       copy file &cName to &cOut
       lSuccess := .t.
    endif

return lSuccess
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! ;) )

User avatar
esgici
Posts: 4345
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Has thanked: 229 times
Been thanked: 80 times
Contact:

Post by esgici » Sun Dec 07, 2008 12:16 pm

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
Viva INTERNATIONAL HMG :D

McMint
Posts: 2
Joined: Wed Nov 19, 2008 3:57 pm

Post by McMint » Sun Dec 07, 2008 7:27 pm

Thanks very much for your help. The application is deploying some updated exe files when they are released by the vendor. We have 5 terminal servers and it is difficult to deploy the files to each TS individually as there are usually 12 exe files to update and any one of them can be in use. Maybe my memory is a bit rusty now on the clipper libraries.

Your assistance/comments much appreciated.

Regards
McMint.

Post Reply