My.Computer.FileSystem.CopyDirectory(Source, Destination, overwrite:=True) > Error >could not complete operation

~OSD~ 2,126 Reputation points
2024-02-19T22:27:51.9633333+00:00

My.Computer.FileSystem.CopyDirectory(Source, Destination, overwrite:=True)

I am getting the following error message while performing the above copy operation.

My.Computer.FileSystem.CopyDirectory could not complete operation on some files and directories see data property of the exception for more details.

Any thoughts on how to bypass /suppress the errors while performing the copy operation?

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,369 questions
{count} votes

Accepted answer
  1. Jiachen Li-MSFT 26,506 Reputation points Microsoft Vendor
    2024-02-21T09:43:03.1533333+00:00

    Hi @~OSD~ , You can use a combination of a try-catch block and ignoring the caught exception.

    Try
        My.Computer.FileSystem.CopyDirectory(Source, Destination, overwrite:=True)
    Catch ex As Exception
        ' Ignore the exception and continue execution
    End Try
    
    

    It merely suppresses any exceptions that occur during the operation, allowing the program to continue execution without being interrupted by error messages.

    However, it's essential to note that by ignoring exceptions, you lose the ability to detect and handle potential issues that may arise during the copy operation. If an error occurs that prevents certain files or directories from being copied successfully, you won't be aware of it, and the operation will continue as if everything succeeded.

    Best Regards.

    Jiachen Li


    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful