tar(在Windows上)c#中的文件列表
题
然后我转到tar然后在C#中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这些文件吗?
<强>更新强>
如果我尝试使用完整路径名,我似乎只能使用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版本。
要避免gzipping,请从参数中删除“z”。
啊,你最好把整个文件夹tar起来,比如把你所有的文件放在一个名为myfolder和tar文件夹的文件夹中,而不是它的内容。
其他提示
仅供参考,有一个托管的tar库,其中包含完整的源代码 http://cheeso.members.winisp.net/srcview。 ?ASPX DIR =焦油&安培;文件= Tar.cs
有一个makefile允许您构建Tar.dll或Tar.exe。 VB中还有一个示例应用程序。
不隶属于 StackOverflow