Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File in Use error 1

Status
Not open for further replies.

PBREP

MIS
Mar 14, 2003
75
US
Hi Gurus:

I'm attempting to create a program that would do a directory prompt (which I get) for the user to select their cus_main.prg file and it would automatically back up the prg & fxp files prior to recompiling. The purpose for the Getdir() is so that the Copy File command will know where to backup the cus_main.prg & fxp files prior to my earlier compile procedure since users do not manual back them up first.

There is no other users accessing this file at this time (ref. error msg. 'File in Use')

Thanks,
PM

GETDIR() && User is prompt to select dir where .prg & fxp resides
COPY FILE CUS_MAIN.PRG TO CUS_MAIN.PAK
COPY FILE CUS_MAIN.FXP TO CUS_MAIN.FAK

cMessageTitle = 'CompileMe'
cMessageText = 'Would you like to search for your directory?'
nDialogType = 4 + 32 + 256
* 4 = Yes and No buttons
* 32 = Question mark icon
* 256 = Second button is default

nAnswer = MESSAGEBOX(cMessageText, nDialogType, cMessageTitle)

DO CASE
CASE nAnswer = 6
Keyboard'enter'
CASE nAnswer = 7
Quit
ENDCASE

GETDIR() && User is prompt to select dir where .prg & fxp resides
COPY FILE *.PRG TO *.BAK
COPY FILE *.FXP TO *.BAK
lcFile = GETFILE('PRG')
if !File( ForceExt(m.lcFile,'fxp') ) && Compile once
compile (lcFile)
endif
do (lcFile)
 
... it would automatically back up the prg & fxp files prior to recompiling...

I'm curious. Why would you want to do that?
First, VFP compiles a program on the fly if it needs to be compiled, and will create a backup of the .prg to .bak before compileing if you've selected that option.
Second, it shouldn't be up to the user to be responsible for locating a .prg. They shouldn't need to have any idea where the .prg or .fxp (s) are, unless they are developers working on the application.

On that note, how about the running application? It could be running the program.

-Dave Summers-
[cheers]
Even more Fox stuff at:
 
Hi Dave:

The third-Pary software can utlized a custom file named "Cus_main.prg". This file is wher you can call custom Functions, Commands and Procedures as you would writing a program from scratch. This of it as a repository, when the third-party program luanches it first read the cus_main.prg file. Now, there is a Update for this third-party software that will update it;s Foxpro Runtime files from v5.0 to 8.0 - it does not copile any customize prg files like the Cus-main.prg. I am creating an executible that will make a backup of the original cus_main.prg and cus_main.fxp for safe keeping then, prompt the user where and what prg to compile. This Cus_main.prg can be located on another drive instead of a local for hardcoding it path would not work. The reason for automating a backup because people rush and run updates, etc without backing up their files first.

Thanks,
~PM
 
So is the original cus_main.prg already being run by the user?
If it has already been executed, it could still be residing in memory unless the app has been totally shut down and the server watchdog has released it.
Also, is the destination in a separate folder too? The .prg or .fxp could have a lock on them if they have been copied by another user.


-Dave Summers-
[cheers]
Even more Fox stuff at:
 
Hi Dave :)

Basically this program is a ONE Time deal (for every install); once this prg is run, the user can then run their Thrid-Party software update which updates the foxpro runtime files from 5.0 to 8.0.

Thanks,
~PM
 
Hi Guys any idea's?

OK this code works fine however, I need to know would be the best way to prompt the user to either select two files (cus_main.prg & cus_main.fxp)or to prompt user where the third-party software (Ascent) is located, because these two files reside in the Ascent root directory; BACKUP and to prompt user is very important in this case since these files will not always be in the same directory (i.e. Ascent software installed on network drive, etc.). Also the way this code compiles I will need to know how I can 'overwrite' the existing cus_main.fxp(ref. compile in vfp 5.0) file, if the CUS_MAIN.FXP already exists it will not do nothing. Some key points in why I am doing this - I am copying both cus_main.prg & cus_main.fxp files which are compiled in vfp 5.0 for backup just in case something went wrong with cus_main compiled under vfp 8.0 at least the original files will remain on disket.

Thank you,
~PM

Working code:

&& Program: CompileMe.exe

close all
answer=messagebox("You want to run CompileMe Backup...",4+32,"CompileMe...")
if answer = 6
do while .t.
if diskspace ("a") = -1
res=messagebox("Drive A: not ready, please verify media and try again",4+64,"Message from CompileMe")
if res = 6
loop
else
return (.f.)
endif
else
set defa to a:
wait window "The unit this list..." Nowait
exit
endif
enddo

if diskspace() < 160
messagebox("Disc Full ! please select an empty disc and try again",0+64,"Message from CompileMe")
else
set safety off
wait window "Preparing to backup files..." nowait
copy file c:\Ascent\Cus_main.prg to a:wait window "Copying file Please wait..." nowait
wait windows "Copying Cus_main.PRG..." timeout 1
copy file c:\Ascent\Cus_main.fxp to a:wait windows "Copying Cus_Main.FXP..."timeout 1
set safety on
messagebox("Backup Completed...",0+64,"CompileMe...")
endif
endif
SET SYSMENU TO DEFA

lcFile = GETFILE('PRG')
if !File( ForceExt(m.lcFile,'fxp') ) && Compile once
compile (lcFile)
endif
do (lcFile)

QUIT

 
Hi PBrep,

(aside: I wouldn't back anything to a floppy - they aren't really reliable)

(1) Instead of moving cus_main.prg & fxp to a different directory, why not leave them in their original directory but rename to eg cus_mainV5.prg and fxp?

This means you only need to ask the user for the Ascent directory, and not rely on them choosing a sensible place to backup to.

(2) I think what you're looking for is something like this
Code:
* Get the user to tell us where the Prg is ;
* The fxp is always in the same directory with the same name
lcPrg= LocFile("Cus_Main.prg", "Please find your Cus_Main.prg?")
lcFxp= ForceExt(lcPrg, "FXP")

* Now make a backup of the prg and fxp
IF File(lcPrg)
  Copy File (lcPrg) To (JustPath(lcPrg) + '\Cus_MainV5Backup.prg'
ENDIF
IF File(lcFxp)
  Copy File (lcFxp) To (JustPath(lcPrg) + '\Cus_MainV5Backup.fxp'
ENDIF
Note - in using LocFile(), I'm assuming that the cus_main.prg can't have any other name?

3) I don't understand what you are trying to compile. Unless your users are being given brand new cus_main files along with the update, then they are still using the old ones. So the old prg and fxp will just stay where they are, and work?

Or have I missed something


4) the title of your post suggests you are getting a 'File in Use' Error. Is that right?
If so, at what point do you get the error?
 
Hi Chris:

The Topic has change since I revised the code. I think you answered my backup problem. I need to recompile the Cus_main.prg before they can accually use the updated version (ref. update Runtime files v8.0). Here are the steps the user needs to take.

a) Run Update on their software (foxpro v8.0 runtime files).
b) Run my program (backs up the files first then recompiles them.

I'll let you know after I try what you suggeted.

Thank you,
~PM
 
Hi again:

Here's where I'm at; not I get two copile errors "Command contains unrecognized phrase/keyword" happens here-> Copy File (lcPrg) To (JustPath(lcPrg) + '\Cus_MainV5Backup.prg'
and here-> Copy File (lcPrg) To (JustPath(lcPrg) + '\Cus_MainV5Backup.fxp'

Thanks PM


* Get the user to tell us where the Prg is ;
* The fxp is always in the same directory with the same name
lcPrg= LocFile("Cus_Main.prg", "Please find your Cus_Main.prg?")
lcFxp= ForceExt(lcPrg, "FXP")

* Now make a backup of the prg and fxp
IF File(lcPrg)
Copy File (lcPrg) To (JustPath(lcPrg) + '\Cus_MainV5Backup.prg'
ENDIF
IF File(lcFxp)
Copy File (lcFxp) To (JustPath(lcPrg) + '\Cus_MainV5Backup.fxp'
ENDIF

lcPrg = GETFILE('PRG')
if !File( ForceExt(m.lcPrg,'fxp') ) && Compile once
compile (lcPrg)
endif
do (lcPrg)

QUIT
 
That's what comes of my posting from a computer where I can't find a copy of foxpro. So I can't check it before posting.

the lines don't compile because I had open brackets without close brackets. This might be better:

Code:
* Now make a backup of the prg and fxp
IF File(lcPrg)
  Copy File (lcPrg) To (JustPath(lcPrg) + ;
      '\Cus_MainV5Backup.prg')
ENDIF
IF File(lcFxp)
  Copy File (lcFxp) To (JustPath(lcPrg) + ;
      '\Cus_MainV5Backup.fxp')
ENDIF


Along with Dave, I don't really believe that you need to compile anything since I also believe that compilation will happen automatically. And I especially can't see that you need to compile anything if everyone is still using their old cus_main: It's already compiled.

You may be concerned that it needs to be recompiled for the new version? As far as I know, it doesn't.
 
Hi Chris:

The old cus_main that was compile under foxpro 5.0, will not run using vfp 8.0 Runtime files hence, the importance to recompile the cus_main prior to user running their program.

Thanks, I'll let you know.

~PM
 
OK this runs smooth (see below) - thanks again Chris. The only other thing I did was renaming the the cus_main.fxp to cus_mainold.fxp 'After' my back-up is made; reason for, in order for the compile to recompile the existing cus_main.prg file the "cus_main.fxp" file must me deleted or renamed. The funny thing the file gets renamed and moved to my windows desktop?? At anyrate it works :)

&& Program: CompileMe.exe

* Get the user to tell us where the Prg is ;
* The fxp is always in the same directory with the same name
wait window "Please locate your Cus_main.prg file." TIMEOUT 2
lcPrg= LocFile("Cus_Main.prg", "prg")
lcFxp= ForceExt(lcPrg, "FXP")

* Now make a backup of the prg and fxp
IF File(lcPrg)
Copy File (lcPrg) To (JustPath(lcPrg) + ;
'\Cus_MainV5Backup.prg')
ENDIF
IF File(lcFxp)
Copy File (lcFxp) To (JustPath(lcPrg) + ;
'\Cus_MainV5Backup.fxp')
ENDIF
IF FILE(lcFxp)
RENAME Cus_main.fxp TO Cus_mainold.fxp
ENDIF

wait window "Please select your Cus_main to be recompiled..." TIMEOUT 2
lcPrg = GETFILE('PRG')
if !File( ForceExt(m.lcPrg,'fxp') ) && Compile once
compile (lcPrg)
endif
do (lcPrg)

QUIT
 
You're right that it won't recompile unless you get rid of the fxp, although I would simply:
DELETE FILE (lcFxp)
rather than copy it. (Note: your code as written will look for the fxp in the wrong place)

You don't need to ask a second time for the cus_main.prg if it's the same one you asked for first time in lcPrg.
 
Your right on the delete :) Thanks again Chris, have an awesome weekend!
~PM

&& FINAL CODE:

* Get the user to tell us where the Prg is ;
* The fxp is always in the same directory with the same name
wait window "Please locate your Cus_main.prg file." TIMEOUT 2
lcPrg= LocFile("Cus_Main.prg", "prg")
lcFxp= ForceExt(lcPrg, "FXP")

* Now make a backup of the prg and fxp
IF File(lcPrg)
Copy File (lcPrg) To (JustPath(lcPrg) + ;
'\Cus_MainV5Backup.prg')
ENDIF
IF File(lcFxp)
Copy File (lcFxp) To (JustPath(lcPrg) + ;
'\Cus_MainV5Backup.fxp')
ENDIF

DELETE FILE (lcFxp)

wait window "Please select your Cus_main to be recompiled..." TIMEOUT 2
lcPrg = GETFILE('PRG')
if !File( ForceExt(m.lcPrg,'fxp') ) && Compile once
compile (lcPrg)
endif
do (lcPrg)

QUIT
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top