当文件名包含空格时,在命令行参数/字符串中发出问题以解压缩.7z文件

时间:2017-08-28 18:52:13

标签: vb.net cmd unzip 7zip

我检查了.7z网站常见问题及其他相关网站。但是没有找到解决这个问题的最佳方案。 当.7z文件名没有空格时,我的cmd正在运行完全解压缩。但是当zip foldername包含空格时,它就不起作用了。

Dim args As String = "e " + """" + zipFileFolder + """" + " -o" + ToFolder + "" + " -p""Password123""" + " -aoa"

示例:Zip文件名:

  

3344-2633-9058-4583_37DB40L1KLJU_15_07_2017__18_40_39_FSserviceLog.7z

然后它运行得很好,但对于这个文件名:

  

6530-0567-9050-2878   AVsetting_WD-WXS1A176FF0E_15_05_2017__17_57_37-F6serviceLog.7z

2878和AVsetting之间有空间,那么我的cmd不起作用。请为此支持我。

请检查以下代码:

Function extract7z(zipFileFolder As String, ToFolder As String)
        Try
            Dim args As String = "e " & """" & zipFileFolder & """" & " -o" & ToFolder & "" & " -p""cyberspa123""" & " -aoa"
            Dim p As New Process
            Dim pInfo As New ProcessStartInfo
            pInfo.FileName = exePath
            pInfo.Arguments = args
            pInfo.WindowStyle = ProcessWindowStyle.Hidden
            p.StartInfo = pInfo
            p.Start()
            p.WaitForExit()
            '   System.Diagnostics.Process.Start(exePath, args)
            'Threading.Thread.Sleep(1000)
            ' System.IO.File.Delete(zipFileFolder)
            For Each foundFile As String In My.Computer.FileSystem.GetFiles(ToFolder)
                Dim check As String = System.IO.Path.GetExtension(foundFile)
                If (check = ".7z") Then
                    Dim zipFolderpath1 As String = System.IO.Path.GetFullPath(ToFolder & "/" & System.IO.Path.GetFileNameWithoutExtension(foundFile))
                    extract7z(foundFile, zipFolderpath1)
                End If
            Next
        Catch ex As Exception
            Console.WriteLine(ex.Message.ToString)
            MessageBox.Show(ex.Message.ToString)

        End Try
    End Function

0 个答案:

没有答案