2

然后我使用 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 这些文件吗?

更新

如果我尝试使用完整路径名,我似乎只能让 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

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

谢谢

4

2 回答 2

3

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

p.StartInfo.Arguments = "czf";

或者

p.StartInfo.Arguments = "-czf";

取决于 tar 版本。

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

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

于 2009-09-17T10:18:40.800 回答
0

仅供参考,在 http://cheeso.members.winisp.net/srcview.aspx?dir=Tar&file=Tar.cs

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

于 2009-12-18T18:10:08.237 回答