【问题标题】:tar (on Windows) a list of files in c#tar(在 Windows 上)c# 中的文件列表
【发布时间】:2024-01-02 00:31:01
【问题描述】:

然后我用 tar 压缩然后 gzip C# 中的文件列表。

我需要一些关于如何将参数设置为 tar 的帮助。

假设我在文件夹 c:\tar\tar.exe 中有 tar.exe 和如下方法:

    private void RunTar(string outputFileName, List<string> fileNamePaths)
    {
        using (Process p = new Process())
        {
            p.StartInfo.FileName = @"c:\tar\tar.exe";
            p.StartInfo.Arguments = //;
            p.Start();
            p.WaitForExit();
        }
    }

注意:fileNamePathsToTar 列表包含完整的 unc 文件名路径,文件可以位于不同的文件夹中。

谁能帮忙提供什么论据

我还在文档中注意到:

-z, --gzip, --ungzip
          filter the archive through gzip

   -Z, --compress, --uncompress
          filter the archive through compress

   --use-compress-program=PROG
          filter through PROG (must accept -d)

不确定如何使用它,但如果我将 gzip.exe 与 tar.exe 放在同一文件夹中我可以在一个步骤中执行我的 tar 然后对这些文件进行 gzip 处理? p>

更新

如果我尝试使用完整路径名,我似乎只能让 tar 处理与 tar.exe 位于同一目录中的文件,但会得到如下信息:

    C:\Tar Test>tar -cf out.tar c:/Tar Test/Text/t1.txt
tar: Cannot add file c:/Tar: No such file or directory
tar: Cannot add file Test/Text/t1.txt: No such file or directory
tar: Error exit delayed from previous errors

我已经尝试过使用斜线 \ 或 / 并在完整路径周围加上引号没有乐趣。

谢谢

【问题讨论】:

  • 我建议在 SuperUser 上询问这个无进程。
  • 试试这个方法 C:\Tar Test>tar -cf out.tar "c:/Tar Test/Text/t1.txt"
  • 嘿,工作 C:\Tar Test>tar -cf out.tar "c:/Tar Test/Text/t1.txt" 什么不工作是 C:\Tar Test>tar - cf "c:/out.tar" "c:/Tar Test/Text/t1.txt"。所以我可以从完整路径读取文件,但不能仅在本地输出到任何位置。
  • 另外,我只能让它对 1 个文件起作用,我希望能够提供文件列表,知道格式吗?

标签: c# windows process gzip tar


【解决方案1】:

要创建存档并 gzip,您应该使用 czf 作为参数,所以

p.StartInfo.Arguments = "czf";

p.StartInfo.Arguments = "-czf";

取决于 tar 版本。

为避免 gzipping,请从参数中删除“z”。

啊,你最好 tar 整个文件夹,比如把你所有的文件放在一个名为 myfolder 的文件夹中,然后 tar 那个文件夹,而不是它的内容。

【讨论】:

  • -cvf 有效,但是当我尝试 czf 时,我得到: C:\Tar Test>tar -czf out.tar t1.txt tar:无法分叉:功能未实现 tar:错误不可恢复:退出现在
  • 试用 out.tar.gz,而不仅仅是 out.tar
  • 实际上不同的错误现在不能fork。 C:\Tar Test>tar -czf out.tar.gz "c:/Tar Test/Text/t1.txt" tar:无法fork:功能未实现tar:错误不可恢复:现在退出
  • 因为 tar 只支持类 unix 的路径。另一种解决方案是“cd”到该目录并使用相对路径运行。
【解决方案2】:

仅供参考,有一个包含完整源代码的托管 tar 库,位于 http://cheeso.members.winisp.net/srcview.aspx?dir=Tar&file=Tar.cs

有一个makefile 允许您构建Tar.dll 或Tar.exe。 VB 中还有一个示例应用程序。

【讨论】:

    最近更新 更多