简体   繁体   English

有没有办法在不包含原始文件的目录结构的情况下创建 TZipfile?

[英]Is there a way to create a TZipfile without including the directory structure of the original files?

The title says it all.标题说明了一切。

I want to create an anonymous Zip file using TZipFile class with simply the file names and no directory structure as it will be distributed to third parties.我想使用 TZipFile 类创建一个匿名 Zip 文件,该类只包含文件名,没有目录结构,因为它将分发给第三方。 Reading through all the responses here and the TZipFile documentation I cannot see a way to do it.通读这里的所有回复和 TZipFile 文档,我看不出有什么方法可以做到。

Do not specify ArchiveFileName parameter of Add() method:不要指定Add()方法的ArchiveFileName参数:

ArchiveFileName is the full path of the file in the archive. ArchiveFileName 是存档中文件的完整路径。 If the parameter is not specified, the default value is ExtractFileName(FileName).如果未指定该参数,则默认值为 ExtractFileName(FileName)。

  with TZipFile.Create do
    try
      Open('D:\MyZipFile.zip', zmWrite);
      Add('D:\SomeFileToAdd.ext');
    finally
      Free;
    end;

This way, you'll find SomeFileToAdd.ext instead of D:\\SomeFileToAdd.ext .这样,您将找到SomeFileToAdd.ext而不是D:\\SomeFileToAdd.ext

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM