Z123456789
Z123456789

Reputation: 11

System.IO.IOExceptions Could not complete the operation since a file already exist in this path

I am trying to copy the file from ftp to local and I am using the code below to do my file copy function and in doing so i am getting an error that files already exist is there any way that i can bypass this and if the file exist it just say do nothing otherwise do the file copy or overwrite the file copied.

    Docopy = True
    If Docopy Then
    ' I want some function here so he can tell that file exist
    ' Write now i am using Kill(CopyTo) but it only works once
        My.Computer.Network.DownloadFile(CopyFrom, CopyTo, UserName, Password)
    End If

Upvotes: 0

Views: 720

Answers (2)

Zeddy
Zeddy

Reputation: 2089

You need to check if the file exists before you do the copy.

Docopy = True
If Docopy Then
    ' I want some function here so he can tell that file exist
    If FileExists("ThisFilenameToTest.txt") = True Then Kill(CopyTo)
    'copy the file
    My.Computer.Network.DownloadFile(CopyFrom, CopyTo, UserName, Password)
End If

Upvotes: 0

Ctznkane525
Ctznkane525

Reputation: 7465

There's some extra parameters you can use for that:

My.Computer.Network.DownloadFile(CopyFrom, CopyTo, UserName, Password, False, 100, True)
  • 5th parameter shows a UI or not
  • 6th parameter is a timeout parameter
  • 7th parameter is an overwrite parameter

Reference: https://msdn.microsoft.com/en-us/library/ms127879(v=vs.110).aspx

Upvotes: 1

Related Questions