我在vb.net中创建了一个项目,该项目以多种格式保存Solid Edge程序集,然后单独压缩这些格式并从目录中删除解压缩的文件。直到最近,该计划工作正常。但是,现在,文件未压缩在目录中。所有发生的事情是扩展.7z的文件创建一级(即我希望文件在C:\ Folder \ New Folder中压缩,但.7z文件在C:\ Folder中创建)。以下是一些项目代码:
' The extensions are stored in the INI file and must be retrieved
Extension = GetIniValue("CADMakros", "FileFormatExtensions3D", "C:\Windows\RTSettings.INI")
' Checks if there are extensions in the INI file
If Extension = "" Or Extension = " " Then
MsgBox("Keine Erweiterungen in «RTSettings.ini» eingetragen")
Exit Sub
End If
' The extensions are separated by a ";" in the INI file
' Therefore, they are split up into separate strings and sorted in the NewExtensions array
'The NewExtensions array does not have a defined size so that an arbitrary number of extensions can be added to the INI file
NewExtensions = Extension.Split(";")
' The spaces are removed from the extension strings
For i = 0 To UBound(NewExtensions)
NewExtensions(i) = NewExtensions(i).Replace(" ", "")
Debug.Print(NewExtensions(i))
Next
' An array containing the filenames is created whose size is dependent on the number of extensions
' Therefore, the array size changes when the INI file is modified
Dim NewFileNames(NewExtensions.Count) As String
Dim zippedFileNames(NewFileNames.Length) As String
' Remove solid edge extension
FileName = Microsoft.VisualBasic.Left(FileName, InStrRev(FileName, ".") - 1)
' Uses the file name as a default response for the input box
FileName1 = InputBox("Dateinamen eingeben", DefaultResponse:=FileName)
If FileName1 = " " Then
MsgBox("Bitte Dateinamen eingeben")
Exit Sub
ElseIf FileName1 = "" Then
Exit Sub
End If
ProgressBar1.Value = 30
' Creates a new file name that acts as the path of the file
For k = 0 To (NewExtensions.Length - 1)
NewFileNames(k) = ChosenFile & "\" & FileName1 & NewExtensions(k)
Next
' The files are saved
For k = 0 To (NewFileNames.Count - 2)
objDocument.SaveAs(NewFileNames(k))
' The progress of the program is sent to the backgroundWorker so it can update the progress bar accordingly
BackgroundWorker1.ReportProgress(30 + (k / (NewFileNames.Count - 2)) * 65)
' The program must be given time to update the progress bar
System.Threading.Thread.Sleep(200)
Next
For j = 0 To NewFileNames.Length - 2
For i = 0 To UBound(NewExtensions)
If NewFileNames(j).Contains(NewExtensions(i)) Then
zippedFileNames(j) = NewFileNames(j).Substring(0, NewFileNames(j).Length - NewExtensions(i).Length)
zippedLocation(j) = zippedFileNames(j) + "-" + NewExtensions(i).Substring(1)
End If
Next
Next
' The files are zipped
Shell(zipPath & " a " & zippedLocation(0) & ".zip " & NewFileNames(0))
Shell(zipPath + " a " + zippedLocation(1) + ".zip " + NewFileNames(1))
Shell(zipPath + " a " + zippedLocation(2) + ".zip " + NewFileNames(2))
'Dim save As New ProcessStartInfo(zipPath)
'save.Arguments = zipPath & " a -tzip " & zippedLocation(0) & ".zip " & NewFileNames(0)
'Process.Start(save)
' The program is given time to zip the file before it is deleted (this ensures the zipped file contains the required information)
Thread.Sleep(2000)
''The unzipped file is deleted from the computer
My.Computer.FileSystem.DeleteFile(NewFileNames(0))
My.Computer.FileSystem.DeleteFile(NewFileNames(1))
My.Computer.FileSystem.DeleteFile(NewFileNames(2))
ProgressBar1.Value = 100
zip命令靠近底部(它们是shell命令)。对于消息框消息感到抱歉,他们是德语,因为我这样做是为了德国公司。 提前谢谢!