5
A
回答
2
- 检查Compress Zip files with Windows Shell API and C#
- 你可以使用SharpZipLib这 是免费的,一个点网项目。
5
您可以使用此的VBScript脚本:
'Adapted from http://www.robvanderwoude.com/vbstech_files_zip.html
strFile = "c:\filename.zip"
strDest = "c:\files"
Set objFSO = CreateObject("Scripting.FileSystemObject")
If Not objFSO.FolderExists(strDest) Then
objFSO.CreateFolder(strDest)
End If
UnZipFile strFile, strDest
Sub UnZipFile(strArchive, strDest)
Set objApp = CreateObject("Shell.Application")
Set objArchive = objApp.NameSpace(strArchive).Items()
Set objDest = objApp.NameSpace(strDest)
objDest.CopyHere objArchive
End Sub
0
我的Excel 2010下试过上述功能Sub UnZipFile(...)
,这是不工作:运行时错误“91”(对象变量或With块未设定)在管线
Set objArchive = objApp.Namespace(strArchive).Items()
和线
Set objDest = objApp.Namespace(strDest)
默默无闻:执行后objDest
仍然没有!
微软的.Namespace()
作为参数接受对象,字符串常量或字符串变量。随着字符串变量经常有可疑的问题,这是需要一个解决办法:
Set objArchive = objApp.Namespace(**CStr(** strArchive **)**).Items()
Set objDest = objApp.Namespace(**CStr(** strDest **)**)
或其他解决办法
Set objArchive = objApp.Namespace(**"" &** strArchive).Items()
Set objDest = objApp.Namespace(**"" &** strDest)
而且objDest.CopyHere objArchive
也没有工作线:目标文件夹仍然是空的!
这里的一个版本,这是工作在Excel 2010中,最可能也是在其他环境中:
Sub UnZipFile(strZipArchive As String, strDestFolder As String)
Dim objApp As Object
Dim vItem As Variant
Dim objDest As Object
Set objApp = CreateObject("Shell.Application")
Set objDest = objApp.Namespace(CStr(strDestFolder))
For Each vItem In objApp.Namespace(CStr(strZipArchive)).Items
objDest.CopyHere vItem
Next vItem
End Sub
0
对于C#或VB的用户,可以从MSDN检查答案: https://msdn.microsoft.com/en-us/library/ms404280(v=vs.100).aspx
对于.net 4.x,这里是MSDN示例代码
using System;
using System.IO;
using System.IO.Compression;
namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
string startPath = @"c:\example\start";
string zipPath = @"c:\example\result.zip";
string extractPath = @"c:\example\extract";
ZipFile.CreateFromDirectory(startPath, zipPath);
ZipFile.ExtractToDirectory(zipPath, extractPath);
}
}
}
相关问题
- 1. 创建Zip文件在Windows和提取Zip文件在Linux中
- 2. 由crontab提取Zip文件
- 3. 从zip中提取文件
- 4. 提取.zip文件在python
- 5. Nodejs从ZIP提取文件
- 6. PHP提取zip文件上
- 7. API提取.zip文件中的7z文件
- 8. 提取文件夹中的Zip文件
- 9. PowerShell的zip文件提取醒目exceptons
- 10. Ionic Zip:提取文件夹的zip文件
- 11. Julia:在Zip文件中提取Zip文件
- 12. 使用库提取ZIp文件JSZip
- 13. 如何提取Windows Phone 7中的zip文件?
- 14. Powershell在最后一个zip文件上失败时提取zip文件。
- 15. 将zip条目提取到另一个Zip文件
- 16. FTP zip文件提取错误
- 17. c#提取目录下的zip文件
- 18. Ruby:下载zip文件并提取
- 19. 蟒蛇不提取zip文件
- 20. 错误而提取zip文件
- 21. 上传Zip文件并提取邮编
- 22. 如何在C#中提取ZIP文件
- 23. Ionic Zip只提取特定文件夹
- 24. 厨师 - 如何提取zip文件
- 25. 在Visual Basic .NET中提取Zip文件
- 26. 提取zip文件到目录
- 27. Hwo提取ZIP文件到tar在postgresql
- 28. powershell - 从zip中提取文件类型
- 29. 提取.zip到%appdata%\子文件夹
- 30. 如何使用php提取.zip文件
谢谢abmv。但第一个链接需要一个外部zip.exe文件。你知道zip.exe的来源吗? 显然SharpZipLib无法解压缩使用WinZip创建的zip文件,可以吗? – Aximili 2009-05-18 23:25:18
我看到它来自另一个项目。我想知道你为什么不能把它合并成一个 – Aximili 2009-05-18 23:59:32