VB.NET Problems opening a folder

0

I have a problem opening a folder. I have a windows form with several buttons, 2 specifically perform the same function, check if the folder exists in the specified route, delete it if it exists and create it again. In turn decompress some files in the indicated folder and open this. In the VS it works correctly but when I convert it into an exe one of the 2 buttons (which have exactly the same code except the name of the folder) does everything but does not open the folder at the end.

    Private Sub Button3_Click_1(sender As Object, e As EventArgs) Handles Button3.Click
    If IO.Directory.Exists(My.Application.Info.DirectoryPath & "\Gibraltar") Then
        IO.Directory.Delete(My.Application.Info.DirectoryPath & "\Gibraltar", True)
        IO.Directory.CreateDirectory(My.Application.Info.DirectoryPath & "\Gibraltar")
    Else
        IO.Directory.CreateDirectory(My.Application.Info.DirectoryPath & "\Gibraltar")
    End If
    Try

        ZipFile.ExtractToDirectory(My.Application.Info.DirectoryPath & "\Gibraltar_wind.zip", My.Application.Info.DirectoryPath & "\Gibraltar")
    Catch ex As Exception

    End Try

    Process.Start("explorer.exe", My.Application.Info.DirectoryPath & "\Gibraltar")
End Sub

Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
    If IO.Directory.Exists(My.Application.Info.DirectoryPath & "\Biscay") Then
        IO.Directory.Delete(My.Application.Info.DirectoryPath & "\Biscay", True)
        IO.Directory.CreateDirectory(My.Application.Info.DirectoryPath & "\Biscay")
    Else
        IO.Directory.CreateDirectory(My.Application.Info.DirectoryPath & "\Biscay")
    End If
    Try

        ZipFile.ExtractToDirectory(My.Application.Info.DirectoryPath & "\Biscay_wind.zip", My.Application.Info.DirectoryPath & "\Biscay")
    Catch ex As Exception

    End Try

    Process.Start("explorer.exe", My.Application.Info.DirectoryPath & "\Biscay")

Where have I made the mistake?

Greetings and thanks

    
asked by user98607 01.09.2018 в 01:39
source

1 answer

0

Well, I do not see any error in your code. The only thing I did was change the ZipFile by System.IO.Compression.ZipFile, and the code stayed that way

Imports System.IO.Compression.ZipFile

Public Class Form1

   Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles Button1.Click
      If IO.Directory.Exists(My.Application.Info.DirectoryPath & "\Gibraltar") Then
         IO.Directory.Delete(My.Application.Info.DirectoryPath & "\Gibraltar", True)
         IO.Directory.CreateDirectory(My.Application.Info.DirectoryPath & "\Gibraltar")
      Else
         IO.Directory.CreateDirectory(My.Application.Info.DirectoryPath & "\Gibraltar")
      End If

      Try
         System.IO.Compression.ZipFile.ExtractToDirectory(My.Application.Info.DirectoryPath & "\Gibraltar_wind.zip", My.Application.Info.DirectoryPath & "\Gibraltar")
      Catch ex As Exception

      End Try

      Process.Start("explorer.exe", My.Application.Info.DirectoryPath & "\Gibraltar")
   End Sub

   Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
      If IO.Directory.Exists(My.Application.Info.DirectoryPath & "\Biscay") Then
         IO.Directory.Delete(My.Application.Info.DirectoryPath & "\Biscay", True)
         IO.Directory.CreateDirectory(My.Application.Info.DirectoryPath & "\Biscay")
      Else
         IO.Directory.CreateDirectory(My.Application.Info.DirectoryPath & "\Biscay")
      End If
      Try

         System.IO.Compression.ZipFile.ExtractToDirectory(My.Application.Info.DirectoryPath & "\Biscay_wind.zip", My.Application.Info.DirectoryPath & "\Biscay")
      Catch ex As Exception

      End Try

      Process.Start("explorer.exe", My.Application.Info.DirectoryPath & "\Biscay")
   End Sub
End Class

and so it works perfectly, open both folders and unzip the file.

    
answered by 03.09.2018 в 14:59