如何创建一个.BAT文件从HTTP服务器下载和解压一个压缩文件?
我们有像http://example.com/folder.zip这样的链接和像C:\Users\UserName\Some mixed Русский English Adress\这样的绝对文件夹链接
如果zip中的文件存在于目录中,则将其删除。
只使用本地窗口(xp、vista、win7等)、BAT函数和文件。
你可以添加代码示例吗?
发布于 2010-05-20 23:30:42
试试这个混合的bat/vbs脚本
@echo off
> %temp%\~tmp.vbs echo sUrl = "http://www.unicontsoft.com/file.zip"
>> %temp%\~tmp.vbs echo sFolder = "c:\temp\unzip"
>> %temp%\~tmp.vbs (findstr "'--VBS" "%0" | findstr /v "findstr")
cscript //nologo %temp%\~tmp.vbs
del /q %temp%\~tmp.vbs
goto :eof
'--- figure out temp file & folder
With CreateObject("WScript.Shell") '--VBS
sTempFile = .Environment("Process").Item("TEMP") & "\file.zip" '--VBS
sTempFolder = .Environment("Process").Item("TEMP") & "\file.zip.extracted" '--VBS
End With '--VBS
'--- download
WiTh CreateObject("MSXML2.XMLHTTP") '--VBS
.Open "GET", sUrl, false '--VBS
.Send() '--VBS
If .Status = 200 Then '--VBS
ResponseBody = .ResponseBody '--VBS
With Createobject("Scripting.FileSystemObject") '--VBS
If .FileExists(sTempFile) Then '--VBS
.DeleteFile sTempFile '--VBS
End If '--VBS
End With '--VBS
With CreateObject("ADODB.Stream") '--VBS
.Open '--VBS
.Type = 1 ' adTypeBinary '--VBS
.Write ResponseBody '--VBS
.Position = 0 '--VBS
.SaveToFile sTempFile '--VBS
End With '--VBS
End If '--VBS
End With '--VBS
'--- extract
With CreateObject("Scripting.FileSystemObject") '--VBS
On Error Resume Next '--VBS
.CreateFolder sFolder '--VBS
.DeleteFolder sTempFolder, True '--VBS
.CreateFolder sTempFolder '--VBS
On Error GoTo 0 '--VBS
With CreateObject("Shell.Application") '--VBS
.NameSpace(sTempFolder).CopyHere .NameSpace(sTempFile).Items '--VBS
End With '--VBS
.CopyFolder sTempFolder, sFolder, True '--VBS
.DeleteFolder sTempFile, True '--VBS
.DeleteFile sTempFile, True '--VBS
End With '--VBS发布于 2010-05-20 22:07:02
如果你真的想使用bat文件,你可以看看:http://www.chami.com/tips/windows/062598W.html
批处理文件将使用名为URL2File的命令行工具
编辑:您的批处理文件应该类似于(您需要有pkunzip或其他cmd-line工具(7-zip f.e.)为此而安装)
@echo off
c:
cd\files
URL2File http://www.server.com/file1.zip file1.zip
for %%f in (file1.zip) do pkunzip %%f c:\user\unziped_files\%%f\https://stackoverflow.com/questions/2874387
复制相似问题