>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.