使用 delphi 2009 在 vi​​sta 上创建目录/文件的 zip 文件的任何函数

发布于 2024-08-09 07:22:12 字数 565 浏览 6 评论 0原文

我正在寻找一种用delphi 进行压缩和压缩的简单方法。我已经查看了 torry delphi 的组件:http://www.torry.net /pages.php?s=99。它们似乎都可以实现我想要的目标,但是使用它们的一些缺点是它们都没有在 delphi 2009 中运行并且非常复杂,这使得我很难将它们移植到 delphi 2009。此外,有关的文档它们很稀缺,至少对我来说是这样。我需要基本的压缩功能,而不需要使用一堆 DLL 的开销。我的任务引导我找到 FSCTL_SET_COMPRESSION,我认为这可以解决问题,但不幸的是这也不起作用。 CREATEFILE 看起来很有希望,直到我尝试它产生与 FSCTL_SET 相同的结果...我知道 Windows 上有一些有限的本机压缩功能。例如,如果右键单击文件或文件夹并选择 -> sendTo ->zipped 文件夹,巧妙地创建了一个压缩存档。我认为如果我能够从 delphi 访问该功能,这将是一个解决方案。另外一个问题是,Linux 是否有自己的本地压缩功能,可以与此类似使用?

I am looking for a simple method of zipping and compressing with delphi. I have already looked at the components at torry delphi:http://www.torry.net/pages.php?s=99. They all seem as though they would accomplish what I want however a few disadvantages to using them is that none of them run in delphi 2009 and are very complex which makes it difficult for me to port them to delphi 2009. And besides, the documentation on them is scarce, well at least to me. I need basic zipping functionality without the overhead of using a bunch of DLLs. My quest lead me to FSCTL_SET_COMPRESSION which I thought would have settled the issue but unfortunately this too did not work. CREATEFILE looked promising, until I tried it yielded the same result as FSCTL_SET... I know that there are some limited native zipping capability on windows. For instance if one right clicks a file or folder and selects -> sendTo ->zipped folder, a zipped archive is smartly created. I think if I was able to access that capability from delphi it will be a solution. On a side issue, does linux have its own native zipping functions that can be used similar to this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

╭⌒浅淡时光〆 2024-08-16 07:22:12

TurboPower 优秀的 Abbrvia 可以在此处下载 D2009,D2010 支持正在进行中,并且已经在 svn 中提供根据他们的论坛

Abbrvia 曾经是一个商业(售价 $$$)产品,这意味着文档相当完整。

TurboPower's excellent Abbrevia can be downloaded for D2009 here, D2010 support is underway and already available in svn according to their forum.

Abbrevia used to be a commercial (for $$$) product, which means that the documentation is quite complete.

清晰传感 2024-08-16 07:22:12

我用Zipforge。为什么将这些移植到 D2009 时出现问题?是因为64位的原因吗?

这是一些示例代码

procedure ZipIt;
var
  Archiver: TZipForge;
  FileName: String;
begin
    try
      Archiver:= TZipForge.create(self);
      with Archiver do begin
        FileName := 'c:\temp\myzip.zip';

        // Create a new archive file
        OpenArchive(fmCreate);

        // Set path to folder with some text files to BaseDir
        BaseDir := 'c:\temp\';

        // Add all files and directories from 'C:\SOURCE_FOLDER' to the archive
        AddFiles('myfiletozip.txt');


        // Close the archive
        CloseArchive;
      end;
    finally
      Archiver.Free;
    end;
end;

I use Zipforge. Why are there problems porting these to D2009? Is it because of the 64bit??

Here is some sample code

procedure ZipIt;
var
  Archiver: TZipForge;
  FileName: String;
begin
    try
      Archiver:= TZipForge.create(self);
      with Archiver do begin
        FileName := 'c:\temp\myzip.zip';

        // Create a new archive file
        OpenArchive(fmCreate);

        // Set path to folder with some text files to BaseDir
        BaseDir := 'c:\temp\';

        // Add all files and directories from 'C:\SOURCE_FOLDER' to the archive
        AddFiles('myfiletozip.txt');


        // Close the archive
        CloseArchive;
      end;
    finally
      Archiver.Free;
    end;
end;
可是我不能没有你 2024-08-16 07:22:12

如果您可以从 Delphi“执行”COM,那么您就可以利用 Windows shell 的内置 zip 功能。它给你良好的基本能力。

在 VBScript 中,它看起来像这样:

Sub CreateZip(pathToZipFile, dirToZip)

    WScript.Echo "Creating zip  (" & pathToZipFile & ") from folder (" & dirToZip & ")"

    Dim fso
    Set fso= Wscript.CreateObject("Scripting.FileSystemObject")

    If fso.FileExists(pathToZipFile) Then
        WScript.Echo "That zip file already exists - deleting it."
        fso.DeleteFile pathToZipFile
    End If

    If Not fso.FolderExists(dirToZip) Then
        WScript.Echo "The directory to zip does not exist."
        Exit Sub
    End If

    NewZip pathToZipFile

    dim sa
    set sa = CreateObject("Shell.Application")

    Dim zip
    Set zip = sa.NameSpace(pathToZipFile)

    WScript.Echo "opening dir  (" & dirToZip & ")"

    Dim d
    Set d = sa.NameSpace(dirToZip)


    For Each s In d.items
        WScript.Echo  s
    Next

    ' http://msdn.microsoft.com/en-us/library/bb787866(VS.85).aspx
    ' ===============================================================
    ' 4 = do not display a progress box
    ' 16 = Respond with "Yes to All" for any dialog box that is displayed.
    ' 128 = Perform the operation on files only if a wildcard file name (*.*) is specified. 
    ' 256 = Display a progress dialog box but do not show the file names.
    ' 2048 = Version 4.71. Do not copy the security attributes of the file.
    ' 4096 = Only operate in the local directory. Don't operate recursively into subdirectories.

    WScript.Echo "copying files..."

    zip.CopyHere d.items, 4

    ' wait until finished
    sLoop = 0
    Do Until d.Items.Count <= zip.Items.Count
        Wscript.Sleep(1000)
    Loop

End Sub

COM 还允许您使用 DotNetZip,这是一个免费下载,可以提供密码- 加密 zip、zip64、自解压档案、unicode、跨区 zip 和其他内容。

If you can "do" COM from Delphi, then you can take advantage of the built-in zip capability of the Windows shell. It gives you good basic capability.

In VBScript it looks like this:

Sub CreateZip(pathToZipFile, dirToZip)

    WScript.Echo "Creating zip  (" & pathToZipFile & ") from folder (" & dirToZip & ")"

    Dim fso
    Set fso= Wscript.CreateObject("Scripting.FileSystemObject")

    If fso.FileExists(pathToZipFile) Then
        WScript.Echo "That zip file already exists - deleting it."
        fso.DeleteFile pathToZipFile
    End If

    If Not fso.FolderExists(dirToZip) Then
        WScript.Echo "The directory to zip does not exist."
        Exit Sub
    End If

    NewZip pathToZipFile

    dim sa
    set sa = CreateObject("Shell.Application")

    Dim zip
    Set zip = sa.NameSpace(pathToZipFile)

    WScript.Echo "opening dir  (" & dirToZip & ")"

    Dim d
    Set d = sa.NameSpace(dirToZip)


    For Each s In d.items
        WScript.Echo  s
    Next

    ' http://msdn.microsoft.com/en-us/library/bb787866(VS.85).aspx
    ' ===============================================================
    ' 4 = do not display a progress box
    ' 16 = Respond with "Yes to All" for any dialog box that is displayed.
    ' 128 = Perform the operation on files only if a wildcard file name (*.*) is specified. 
    ' 256 = Display a progress dialog box but do not show the file names.
    ' 2048 = Version 4.71. Do not copy the security attributes of the file.
    ' 4096 = Only operate in the local directory. Don't operate recursively into subdirectories.

    WScript.Echo "copying files..."

    zip.CopyHere d.items, 4

    ' wait until finished
    sLoop = 0
    Do Until d.Items.Count <= zip.Items.Count
        Wscript.Sleep(1000)
    Loop

End Sub

COM also allws you to use DotNetZip, which is a free download, that does password-encrypted zips, zip64, Self-extracting archives, unicode, spanned zips, and other things.

遗失的美好 2024-08-16 07:22:12

我个人使用 VCL Zip,它在 D2009 和 D2010 上运行得非常好。在撰写本文时,它的价格确实是 120 美元,但非常简单、灵活,最重要的是快速。

感兴趣,请查看 VCLZIP 并下载该链接

如果您对代码

VCLZip1.ZipName := ‘myfiles.zip’;
VCLZip1.FilesList.add(‘c:\mydirectory\*.*’);
VCLZip1.Zip;

:这是基本 zip 所需的全部内容,您当然可以设置压缩级别、目录结构、zip 流、解压缩流等等。

希望这能有所帮助。

关于

Personally I use VCL Zip which runs with D2009 and D2010 perfectly fine. it does cost $120 at the time of this post but is very simple, flexible and most of all FAST.

Have a look at VCLZIP and download the trail if your interested

code wise:

VCLZip1.ZipName := ‘myfiles.zip’;
VCLZip1.FilesList.add(‘c:\mydirectory\*.*’);
VCLZip1.Zip;

is all you need for a basic zip, you can of course set compression levels, directory structures, zip streams, unzip streams and much more.

Hope this is of some assistance.

RE

阿楠 2024-08-16 07:22:12

看一下这个开源 SynZip 单元。它的解压速度比 Delphi 附带的默认单元更快,并且会生成更小的 exe(crc 表在启动时创建)。

不需要外部 dll。适用于 Delphi 6 至 XE。 Delphi 的 Unicode 版本没有问题。全部集中在一个单元中。

我只是做了一些更改来处理 Zip 内容中的 Unicode 文件名,不仅是 Win-Ansi 字符集,还包括任何 Unicode 字符。欢迎反馈。

Take a look at this OpenSource SynZip unit. It's even faster for decompression than the default unit shipped with Delphi, and it will generate a smaller exe (crc tables are created at startup).

No external dll is needed. Works from Delphi 6 up to XE. No problem with Unicode version of Delphi. All in a single unit.

I just made some changes to handle Unicode file names inside Zip content, not only Win-Ansi charset but any Unicode chars. Feedback is welcome.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文