Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Alternate to Rename command
Message
From
10/10/2005 14:40:16
Dragan Nedeljkovich (Online)
Now officially retired
Zrenjanin, Serbia
 
 
To
10/10/2005 09:36:45
General information
Forum:
Visual FoxPro
Category:
Other
Environment versions
Visual FoxPro:
VFP 6 SP5
OS:
Windows XP SP2
Network:
Windows 2000 Server
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01057642
Message ID:
01057736
Views:
9
>Is there an alternate way to 'Rename' a file other than Rename command? I need somthing that will return a value as to wheather it worked or not, or haow to trap for errors and return a message to user. I have error trapping that logs the error and returns control backto the program but the user never knows the routine failed. This happens when the renamed from file is open or the rename file to already exists.

I've had this problem with some files (Excel sheets) that need to be generated regularly, and it was happening that someone would have a few of them open. The first part of the process was to move them all into archive directory - and of course the open ones couldn't be moved.

I basically tried to open them low-level, and if fopen() returned -1, a-ha, someone's got you open. I wouldn't even try to rename that file, I'd just copy it (using strtofile(filetostr(oldname), newname), which works for files someone has open.

Then (if the user had the rights to override), I'd go on creating new files, and for the old ones that were still there, I'd try in a loop to name them forceext(oldname+"_01", "xls"), then with "_02" etc. So the new file would be written there, the old would eventually be moved (mostly next time) and I still had all the files archived.

The whole thing changed recently, I'm creating a new directory each time, so the problem completely vanished.

back to same old

the first online autobiography, unfinished by design
What, me reckless? I'm full of recks!
Balkans, eh? Count them.
Previous
Reply
Map
View

Click here to load this message in the networking platform