Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用VBA列出zip(TAR)文件的内容_Vba_Shell - Fatal编程技术网

使用VBA列出zip(TAR)文件的内容

使用VBA列出zip(TAR)文件的内容,vba,shell,Vba,Shell,我试图编写更大的代码,通过电子邮件发送TAR文件中的文件列表,然后通过电子邮件发送,但最后一件事是TAR文件内容的实际列表。到目前为止,我尝试的代码是: Public r As Long Sub Test() Dim strPath As String Dim sh, n, x, i 'Change Path To Suit 'strPath = ThisWorkbook.Path & "\" strPath = "H:\99 - Temp\"

我试图编写更大的代码,通过电子邮件发送TAR文件中的文件列表,然后通过电子邮件发送,但最后一件事是TAR文件内容的实际列表。到目前为止,我尝试的代码是:

Public r As Long
Sub Test()

Dim strPath As String
Dim sh, n, x, i


'Change Path To Suit
'strPath = ThisWorkbook.Path & "\"
strPath = "H:\99 - Temp\"


Set sh = CreateObject("Shell.Application")
x = GetFiles(strPath, "*.TAR", True)
r = 7

For Each i In x
Set n = sh.NameSpace(i) <----------
Recur sh, n
Next i
End Sub

Sub Recur(sh, n)
Dim i, subn, x As Long, p As Long


For Each i In n.Items
If i.isfolder Then
Set subn = sh.NameSpace(i)
Recur sh, subn
Else
p = LastPos(i.Path, "\")

Debug.Print Mid(i.Path, p + 1)
'Cells(r, 1) = Mid(i.Path, p + 1)
r = r + 1
End If
Next i
End Sub


Function GetFiles(StartPath As String, FileType As String, SubFolders As Boolean) As Variant
StartPath = StartPath & IIf(Right(StartPath, 1) = "\", vbNullString, "\")
GetFiles = Split(Join(Filter(Split(CreateObject("WScript.Shell").Exec("CMD /C DIR """ & StartPath & 
FileType & """ " & IIf(SubFolders, "/S", vbNullString) & " /B /A:-D").StdOut.ReadAll, vbCrLf), ":"), 
"#"), "#")
End Function


Function LastPos(strVal As String, strChar As String) As Long
LastPos = InStrRev(strVal, strChar)
End Function
Public r尽可能长
子测试()
将strPath设置为字符串
暗sh,n,x,i
"因地制宜,
'strPath=ThisWorkbook.Path&'\'
strPath=“H:\99-Temp\”
Set sh=CreateObject(“Shell.Application”)
x=GetFiles(strPath,“*.TAR”,True)
r=7
对于x中的每个i

从这里使用
ShellRun
概念设置n=sh.NameSpace(i):

使用Win10

子测试仪()
暗p、s、col、e
p=“C:\Blah\Temp\Temp.tar”
设置col=ShellOutput(“tar-tf”“”和p&”“)
调试。打印列数;“返回的条目”
调试。打印“------------------------------”
对于每个列中的e
调试。打印e
下一个e
端接头
'运行shell命令,将输出作为行集合返回
公共函数ShellOutput(sCmd作为字符串)作为集合
暗淡的线条,作为收藏的颜色
Set col=新集合
使用CreateObject(“WScript.Shell”).Exec(sCmd.StdOut
而不是
sLine=.ReadLine
如果是sLine“”,则列添加sLine
温德
以
设置ShellOutput=col
端函数

太好了,谢谢
Sub test99()
Dim n As Variant

Set sh = CreateObject("shell.application")
Set n = sh.NameSpace("H:\99 - Temp\test.TAR")
For Each i In n.Items <-------------
Debug.Print i.Path
Next
End Sub