Vbscript 使用从文本文件加载的字符串运行外部命令
我正在尝试自动提取不同目录中的一组压缩文件(.ARJ) 我目前使用2个文本文件存储2位信息:Vbscript 使用从文本文件加载的字符串运行外部命令,vbscript,winrar,Vbscript,Winrar,我正在尝试自动提取不同目录中的一组压缩文件(.ARJ) 我目前使用2个文本文件存储2位信息: 压缩文件的当前位置和名称(ARJFileNames.txt) 示例-D:\u Work\u Splunk\u TestBed\Branch00\LOAN.ARJ 要提取到的文件的目标位置(ARJFileLocations.txt) 示例-D:\u工作\u Splunk\u试验台\Branch00 我试图使用WScript.Shell命令运行WinRAR,将文件从当前位置提取到目标位置 我的问题是,当我从
WScript.Shell
命令运行WinRAR,将文件从当前位置提取到目标位置
我的问题是,当我从循环中调用外部命令时,我似乎无法获得正确的语法,以便在实际调用WinRar及其开关/命令的同时附加从文本文件中提取的字符串
这是我目前的代码:
”声明常量
读取常数=1,写入常数=2,外观常数=3
'声明变量
Dim fso、strFilePath、strFileName、fFilePath、fFileName、objShell、WinRAR、strCMD、SevenZip、ARJ
设置fso=CreateObject(“Scripting.FileSystemObject”)
设置objShell=WScript.CreateObject(“WScript.shell”)
'打开文本文件以供使用
设置strFilePath=fso.OpenTextFile(“D:\\u Work\\u Splunk\\u TestBed\ARJFileLocations.txt”,用于读取,三态为false)
设置strFileName=fso.OpenTextFile(“D:\\u Work\\u Splunk\\u TestBed\ARJFileNames.txt”,用于读取,三态为false)
直到strFilePath.AtEndOfStream
fFilePath=strFilePath.ReadLine'获取ARJ文件的位置
fFileName=strFileName.ReadLine'获取ARJ文件内容的目标位置
'将命令存储为1个字符串'
strCMD=“winrar x-y”和“&fFileName&”&fFilePath
'在CLI中运行命令'
运行strCMD
环
“清理
设置strFilePath=Nothing
设置strFileName=Nothing
设置objShl=Nothing
参考
如果在命令提示符下键入命令行,命令行最终应显示(通过Wscript.Echo命令验证)
:
如果fDLocation
或fTLocation
包含空格,请使用以下命令
Command = """" & WinRAR & "\WinRAR.exe"" X """ & fDLocation & """ """ & fTLocation & """"
' ↑↑ ↑↑ ↑↑ ↑↑↑↑
' results to
' "D:\Program Files\WinRAR\WinRAR.exe" X "ARJ Location" "Target Location"
' ↑ ↑ ↑ ↑ ↑ ↑
此外,我会考虑运行脚本和<代码> Wrrar .exe < /C>程序同步(参见文章)如下:
Dim intRunResult
Do Until strARJLocations.AtEndOfStream
fDLocation = strARJLocations.ReadLine 'Get the location of the ARJ file'
fTLocation = strTargetLocation.ReadLine 'Get the target location for ARJ file contents'
Command = """" & WinRAR & "\WinRAR.exe"" X """ & fDLocation & """ """ & fTLocation & """"
intRunResult = objShell.Run ( Command, 1, True)
Loop
Dim intRunResult
Do Until strARJLocations.AtEndOfStream
fDLocation = strARJLocations.ReadLine 'Get the location of the ARJ file'
fTLocation = strTargetLocation.ReadLine 'Get the target location for ARJ file contents'
Command = """" & WinRAR & "\WinRAR.exe"" X """ & fDLocation & """ """ & fTLocation & """"
intRunResult = objShell.Run ( Command, 1, True)
Loop