FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister   Add to FavoritesAdd to Favorites
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in    RSS Get RSS Feed  


CopyFile TIP

 
Post new topic   Reply to topic    Macro Scheduler and Windows Automation Forum Index -> General Discussion
View previous topic :: View next topic  
Author Message
Bob Hansen
Automation Wizard


Joined: 24 Sep 2002
Posts: 2414
Location: Salem, New Hampshire, US
Reputation: 300
votes: 17
Earn Points, Win a T-Shirt

PostPosted: Tue Jan 21, 2003 12:18 am    Post subject: CopyFile TIP Reply with quote

I recently found out (probably knew it before, and forgot it Embarassed) that it is possible to lose a file when doing CopyFile.

I had done Let>CF_OVERWRITE=1, and then did a CopyFile>Source,Destination. I had not done any checks for copy success and later I was having some random problems based on the destination file. Confused

Working back I found that sometimes the Destination file did not exist. Going back further, I found that it did not exist because the Source file was in use and the CopyFile did not copy to destination. Confused

But the "old" Destination file had already been deleted. Exclamation Result was that I lost the "old" file, did not get a copy of the "new" file, and trouble followed.

Idea Simplified solution:
===============================
//Rename old copy to keep for restoration if needed
MoveFile>old,temp

CopyFile>new, old
IfFileExists>old,Good

Message>Error copying new file to old
//Keep original "old" file that was deleted when CopyFile started
MoveFile>temp,old
GoTo>ErrorRoutine

Label>Good
//Remove original "old" file, not needed any longer
DeleteFile>temp
Goto>End

Label>ErrorRoutine
.....
.....
.....

Label>End

==================================
The simplified script above only does a check on the CopyFile instruction, but a verification could be done after each MoveFile, CopyFile, DeleteFile instruction.

I haven't done any test at this point to see what happens when CF_OVERWRITE is at default=0. I do not think this problem will occur. But if you do use CF_OVERWRITE=1, you should take the extra steps to copy the destination file until you are sure that the replacement file has been copied successfully.

Now that this has been written out, it seems obvious to me that this would happen. (Also need to follow up on the recent messages in the forum on identifying locked files).

As a general practice, all copy/write/delete routines should be verified, but those extra programming steps never seem important enough to put in the extra effort/time.

Idea Hope this is a helpful TIP to someone else. Arrow
_________________
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

Did this message help you? If so please reward the poster with Reputation Points? Reward Points
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:    View previous topic :: View next topic  
Post new topic   Reply to topic    Macro Scheduler and Windows Automation Forum Index -> General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group