Because a file or directory with the same name already exists.

Jan 19, 2012 at 9:21 PM

My code is this:

Dim args(2) As String
Private Sub Buttonbackupjar_Click(sender As System.Object, e As System.EventArgs) Handles Buttonbackjar.Click
        Try
            Using zip As ZipFile = New ZipFile("jar")
                ' Add the file to the Zip archive's root folder.
                zip.AddFile(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) & "\AppData\Roaming\.minecraft\bin\minecraft.jar")
                ' Save the Zip file.
                zip.Save(Application.StartupPath & "\backup\backupjar.zip")
            End Using
        Catch ex As Exception
            MessageBox.Show("Error adding file to archive. " + ex.Message)
        End Try
End Sub

Private Sub Buttonjarre_Click(sender As System.Object, e As System.EventArgs) Handles Buttonjarre.Click
        args(0) = Application.StartupPath & "\backup\backupjar.zip"
        args(1) = (Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) & "\AppData\Roaming\.minecraft\bin\minecraft.jar")
        Dim worker As System.Threading.Thread
        worker = New System.Threading.Thread(New System.Threading.ParameterizedThreadStart(AddressOf Unzipjar))
        worker.Start(args)
        Labeljarentries.Visible = True
        Labeljarentries.Enabled = True
        Try
        Catch ex2 As Exception
            Labeljarentries.Text = ("Exception: " & ex2.ToString)
        End Try
End Sub

Private Sub Unzipjar(ByVal args As String())
        Using zip As ZipFile = ZipFile.Read(args(0))
            Dim entry As ZipEntry
            For Each entry In zip
                Updatejar(entry.FileName)
                entry.Extract(args(1), ExtractExistingFileAction.OverwriteSilently)
            Next
            Updatejar(String.Format("{0} files restored!", zip.Entries.Count))
        End Using
End Sub

Private Sub Updatejar(ByVal filename As String)
        If Me.InvokeRequired Then
            '' invoke on the proper thread 
            Me.Invoke(New Action(Of String)(AddressOf Updatejar), New Object() {filename})
        Else
            Labeljarentries.Text = filename
            MyBase.Update()
        End If
End Sub

My error is this:

"Cannot create "C:\Users\Soren\AppData\Roaming\.minecraft\bin\minecraft.jar" because a file or directory with the same name already exists."

My backupjar.zip file have many subfolder! "\backup\backupjar.zip\Users\Soren\AppData\Roaming\.minecraft\bin\"

 

What have i done wrong? Please help me.

Btw folder extraction works fine! (Great library!)