gpt4 book ai didi

c# - tar(在 Windows 上)C# 中的文件列表

转载 作者:可可西里 更新时间:2023-11-01 10:10:14 34 4
gpt4 key购买 nike

然后我在 C# 中对文件列表进行 tar 和 gzip 压缩。

我需要一些关于如何将参数设置为 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

我已经尝试过使用\或/两种方式使用斜线,并且在完整路径周围使用引号没有任何乐趣。

谢谢

最佳答案

要创建一个存档并对其进行 gzip,您应该使用 czf 作为参数,所以

p.StartInfo.Arguments = "czf";

p.StartInfo.Arguments = "-czf";

取决于 tar 版本。

为避免 gzip 压缩,请从参数中删除“z”。

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

关于c# - tar(在 Windows 上)C# 中的文件列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1437875/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com