【发布时间】:2023-02-10 18:13:51
【问题描述】:
我正在尝试为 Altap Salamander 制作一个 VBScript,它将从当前选择中获取文件并将它们单独存档为 TAR。
下面的大部分代码都有效,但第 27 行的 shell 命令返回 Shell 错误 1,并且没有创建任何 TAR 文件。
Dim FSO, WshShell
Set FSO = CreateObject("Scripting.FileSystemObject")
Set WshShell = CreateObject("WScript.Shell")
Dim Items, Item, result
' Pick the collection of items to make the list from.
If Salamander.SourcePanel.SelectedItems.Count = 0 Then
If Salamander.MsgBox("No items are selected. Do you want to make list from all items in the panel?", 4, "Question") = 6 Then
Set Items = Salamander.SourcePanel.Items
End If
Else
Set Items = Salamander.SourcePanel.SelectedItems
End If
ReDim args(Items.Count - 1)
For i = 0 To Items.Count - 1
args(i) = Items.Item(i).Path
Next
tarFilePath = FSO.GetParentFolderName(args(0))
For i = 0 To UBound(args)
objFile = args(i)
tarFileName = FSO.GetFile(objFile).Name & ".tar"
tarFile = tarFilePath & "\" & tarFileName
result = WshShell.Run("cmd.exe /c ""C:\Program Files\7-Zip\7zFM.exe"" a -ttar -r """ & tarFile & """ """ & FSO.GetFile(objFile).Path & """", 0, True)
Next
If result = 0 Then
result = "Shell ran successfully"
Else
result = "Shell error " & result
End If
MsgBox result, vbInformation, "Archiving Complete"
我试过将 7z.exe 更改为 7zG.exe 和 7zFM.exe,添加和删除引号以及调试。
我也试过 here 的 CMD 方法,但它们对我来说没有多大意义,我没有得到任何工作。
我应该怎么做才能使这项工作?
【问题讨论】:
-
您是否使用
MsgBox验证了您的.Run字符串?FSO.GetFile(objFile).Path和tarFilePath一样吗?如果是这样,那是可以简化的事情。也不需要Cmd.exe /c。直接运行 Zip 程序即可。 -
我还将创建一个 .vbs 版本的代码以在 Altap Salamander 之外进行测试。这可能有助于简化调试。