如何创建 .BAT 文件以从 HTTP 服务器下载和解压缩 zip 文件?
我们有像这样的链接和像这样http://example.com/folder.zip
的绝对文件夹链接C:\Users\UserName\Some mixed Русский English Adress\
如果 zip 中的文件存在于目录中,请覆盖它们。
仅使用本机 Windows(xp vista win7 等)BAT 函数和文件。
请您添加代码示例。
如何创建 .BAT 文件以从 HTTP 服务器下载和解压缩 zip 文件?
我们有像这样的链接和像这样http://example.com/folder.zip
的绝对文件夹链接C:\Users\UserName\Some mixed Русский English Adress\
如果 zip 中的文件存在于目录中,请覆盖它们。
仅使用本机 Windows(xp vista win7 等)BAT 函数和文件。
请您添加代码示例。
试试这个混合 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
如果您真的想使用 bat 文件,您可以查看: http: //www.chami.com/tips/windows/062598W.html
批处理文件将使用名为:URL2File 的命令行工具
编辑:您的批处理文件应该类似于(您需要为此安装 pkunzip 或其他命令行工具(7-zip fe))
@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\
下载和解压缩.bat:
powershell -command "Start-BitsTransfer -Source http://example.com/folder.zip -Destination folder.zip"
powershell -command "Expand-Archive folder.zip folder/to/extract"
下载folder.zip
到当前目录(或任何其他 - 必须存在)。提取folder.zip
到folder/to/extract
(自动创建)。
由于 Windows 7 包含 Powershell 恕我直言,您可以使用此 powershell 脚本:http ://bwain-dump.blogspot.com/2009/01/powershell-script-to-unzip-many-files.html
如果不是powershell,那么我认为,没有本地的方法可以做到这一点。您可以使用提供命令行的 zip 实用程序,例如 7-zip
如果您的 PC 与任何其他 Windows PC 一样,它应该安装了 powershell。如果您尝试从 cmd 行或批处理脚本运行它,没问题,您可以将 powershell 这个词放在任何命令的前面,让它通过 cmd 提示控制台运行它!首先,您应该将希望人们下载的文件上传到投递箱。然后获取一个可共享的链接,将 www.dropbox.com 替换为 dl.dropboxusercontent.com 以创建不需要人们单击下载按钮的直接链接。然后制作这样的脚本:
start /MAX *drop box link*
timeout 3 >nul
powershell Expand-Archive C:\Users\%USERNAME%\Downloads\*file name* C:/
这将下载文件并将其解压缩到 C:/ 驱动器,它很简单,并且完全符合它的需要,不适用于 .RAR 文件。我希望这能解决你的问题。