moving file ine script task

  • hi,

    I am moving a file in script task using the following code

    For Each f As String In Directory.GetFiles(DirToCreate)

    If f IsNot Nothing Then

    Dim i As String = f.Substring(97, CInt(IIf(Convert.ToInt32(f.LastIndexOf("/")) < 0, _

    14, Convert.ToInt32(f.LastIndexOf("/"))))).Replace("/", "\")

    File.Move(f, "C:\TEST\" + i)

    End If

    Next

    the problem is if the file already exists then it will say Cannot create a file when that file already exists. now is it possible to overwrite the existing file, if so can you help me how to do it?

    thanks

  • I have to admit I'm writing this without checking, but it's probably something like this:

    If FileExists("C:\Test\" + i)

    DeleteFile("C:\Test\" + i)

    End If

    File.Move(f,"C:\Test\" + i)

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply