我正在尝试使用
TZipFile.ZipDirectoryContents()
Run Code Online (Sandbox Code Playgroud)
像这样:
TZipFile.ZipDirectoryContents('Test.PCF', WorkingDir);
Run Code Online (Sandbox Code Playgroud)
如果我正确读取它,它应该将文件夹"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."
Run Code Online (Sandbox Code Playgroud)
有两件事令我困惑:
它说无法打开文件.还没有test.pcf.我希望这会创造它.
它说无法访问文件.这是因为它还没有创建吗?我使用这个功能吗?如果是这样,我如何从文件夹位置创建一个zip文件?
Rob*_*ank 17
我测试了你的代码,它的失败方式与报告方式相同.
然后我通过运行WinZip手动创建了一个空的zip文件.
然后运行你的代码,它运行正常.
看来zip文件必须已经存在,ZipDirectoryContents才能工作.
以编程方式创建zip文件:
myZipFile := TZIpFile.Create;
myZipFile.Open('c:\myfolder\newzipfile.zip', TZipMode.zmWrite);
myZipFile.Close;
myZipFile.Free;
Run Code Online (Sandbox Code Playgroud)
这条线将起作用:
TZipFile.ZipDirectoryContents('c:\myfolder\newzipfile.zip', WorkingDir);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3050 次 |
| 最近记录: |