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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem copying folder using Scripting.FileSystemObject 2

Status
Not open for further replies.

jjjt

Technical User
Sep 15, 2002
34
GB
Hi,

We're using VFP8 and the following code to copy a folder:

oFSO = CREATEOBJECT("Scripting.FileSystemObject")
oFSO.copyfolder(source, destination,.F.)

and it works fine until such time as somebody is editing one of the files contained in the folder, at which point we get a "COM command failed to execute" error. Rather than getting this message, what we want to do is trap that error and let the user know that the process cannot continue because files are in use.

I was hoping that the "copyfolder" method might return some sort of error reason code that we could trap and then act accordingly, but as far as I can see that does not appear to be the case... Is there any way of getting the method to return something more useful than "COM command failed to execute"?

Thanks in advance for any advice.

 
jjjt,
The COMRETURNERROR( ) Function is what you are looking for - check out the VFP Help File.

You can use the new TRY ... CATCH error handling, or the old ON ERROR technique.

Rick
 
jjjt

The WinAPI call CopyFile() allows you to copy files that are in use, one exclusion being VFP tables.

If also returns a numeric value indicating the success or otherwise of the operation as opposed to producing an error should the operation fail.

FAQ184-2483 - answering getting answered.​
Chris [pc2]
PDFcommander[sup]tm[/sup].net
PDFcommander[sup]tm[/sup].co.uk
 
Chris, Rick,

Thanks for the input - COMRETURNERROR() is exactly what I was looking for. With regards to the WinAPI, what are its relative merits in relation to the Scripting Object? I think I am right in saying that if we use the Scripting Object, the user has to have the right version installed on their machine, and of course we have no control over that, which would tend to be an argument in favour of using WinAPI. Are there any other factors that we should be taking into account when deciding which of the options to use?
 
jjjt

Thanks for the star

The WinAPI call CopyFile() works on single files as opposed to a folder so you would need to use ADIR() and then loop through the resultant array and copy each file, regardless of whether or not it's in use by another application, VFP and other tables excepted.

The benefit is that you can use a progressbar and isolate and report on any files that were not copied.

An example can be found at
Using WSH depends on its availability on the user's machine, and therefore I always use CopyFile() if suitable.

FAQ184-2483 - answering getting answered.​
Chris [pc2]
PDFcommander[sup]tm[/sup].net
PDFcommander[sup]tm[/sup].co.uk
 
Makes sense. Thanks Chris.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top