9

我正在尝试使用

TZipFile.ZipDirectoryContents()

像这样:

TZipFile.ZipDirectoryContents('Test.PCF', WorkingDir);

如果我没看错,它应该将文件夹“workingdir”的内容保存到名为 Test.pcf 的文件中。

现在当我这样做时,我得到错误::

Raised exception class EFOpenError with message Cannot open file
...test.pcf. The process cannot access the file because its being used by another process."

有两件事让我感到困惑:

  1. 它说它无法打开文件。还没有 test.pcf。我希望这会创造它。

  2. 它说无法访问文件。这是因为它还没有创建吗?我在使用这个功能吗?如果是这样,我将如何从文件夹位置创建一个 zip 文件?

4

1 回答 1

17

我测试了您的代码,它以与您报告的相同的方式失败。

然后我通过运行 WinZip 手动创建了一个空的 zip 文件。

然后运行你的代码,它运行良好。

似乎 zip 文件必须已经存在才能使 ZipDirectoryContents 工作。

以编程方式创建 zip 文件:

  myZipFile := TZIpFile.Create;
  myZipFile.Open('c:\myfolder\newzipfile.zip', TZipMode.zmWrite);
  myZipFile.Close;
  myZipFile.Free;

然后这条线将起作用:

  TZipFile.ZipDirectoryContents('c:\myfolder\newzipfile.zip', WorkingDir);
于 2012-06-17T01:39:54.037 回答