【发布时间】:2013-10-16 04:15:12
【问题描述】:
基本代码:
string startPath = @"C:\intel\logs";
string zipPath = @"C:\intel\logs-" + DateTime.Now.ToString("yyyy_dd_M-HH_mm_ss") + ".zip";
ZipFile.CreateFromDirectory(startPath, zipPath);
错误:进程无法访问文件“path_to_the_zip_file_created.zip”,因为它正被另一个进程使用。
上述设置在我安装了 Visual Studio 的 Windows 7 上运行良好,但在 Windows Server 2008R2 上运行时出现上述错误消息。
我检查了防病毒日志,它没有阻止应用程序,也没有锁定创建的 zip 文件。
【问题讨论】:
-
你发现问题了吗?
-
这正是发生在我身上的事情。
-
压缩文件正在尝试压缩文件夹的所有内容,但在读取文件夹的同时写入。这会导致它尝试自行压缩。下面的答案表明您不能将 zip 文件存储在您正在压缩的文件夹中。
-
@KyleShrader 不,他正在将“日志”压缩到“intel”并将结果放入“intel”。