At 10:10 AM 8/28/2006 -0400, [EMAIL PROTECTED] wrote:
Hi,

What's the best way to deal with replacing a file that's in use? I have a
FoxPro program that imports a text file, massages it a bit, loads it into
...
Wondering how other people have dealt with this.

The way we've approached this in the past is to NOT try to replace a file that is in use. So, basically, this would be the approach:

- Check 'destination' file to make sure it can be opened (e.g with an FOPEN command) - Open the destination file (to prevent others from opening it) (after you FCLOSE'd of course, and use Automation to open the file)
- Do you mods, update the destination file
- Close the destination file


If that first check fails, you wait. Or send an email to someone. Or pop-up a message in your program stating why the update cannot occur.

The above sort of assumes you're talking about a file that sits on a server which everyone tries to access. If you're talking about a file on the local machine you can simplify things a bit. That is, you know the 'local machine' has the file open so you can tell the user it can't complete because the file is in use (and they should go check Excel, or hopefully OpenOffice <g>, and close down that file). Even then I'd strongly advise against programmatically closing down a file the user has open. It may be possible to do that through Excel automation, but you don't know what they're doing and you shouldn't take the risk of trashing something they're looking at.

-Charlie


_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/profox
OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.

Reply via email to