tar(在 Windows 上)c# 中的文件列表
然后我用 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?
更新
如果我尝试使用完整路径名,我似乎只能让 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
我已经尝试使用斜杠两种方式 \ 或/ 并且在完整路径周围加上引号没有乐趣。
谢谢
I then to tar and then gzip a list of files in C#.
I need some help with how to set the arguments to tar.
Say I have tar.exe in a folder c:\tar\tar.exe and a method like the following:
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();
}
}
Note: the fileNamePathsToTar list has the full unc filename paths and the files can be in different folders.
Can anyone please help with what arguments to supply.
Also I notice in the documentation:
-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)
Not sure how to use this but if I place the gzip.exe in the same folder as tar.exe can I perform my tar and then gzip of these files all in one step?
Update
I can only seem to get tar to work on files in the same directory as tar.exe if I try a full path name I get something like:
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
I've tried with the slashes both ways \ or / and with quotes around the full path no joy.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要创建存档并对其进行 gzip,您应该使用 czf 作为参数,因此
或
取决于 tar 版本。
为了避免 gzip 压缩,请从参数中删除“z”。
啊,你最好 tar 整个文件夹,比如将所有文件放在一个名为 myfolder 的文件夹中,然后 tar 该文件夹,而不是它的内容。
to create an archive and gzip it, you should use czf as arguments, so
or
depending on tar version.
to avoid gzipping, remove the 'z' from the arguments.
ah, and you'd better tar an entire folder, like put all your file in a folder named, e.g., myfolder and tar that folder, not it's content.
仅供参考,有一个托管 tar 库,其完整源代码位于
http://cheeso.members.winisp.net/ srcview.aspx?dir=Tar&file=Tar.cs
有一个 makefile 允许您构建 Tar.dll 或 Tar.exe。还有一个 VB 示例应用程序。
FYI, there's a managed tar library with full source available at
http://cheeso.members.winisp.net/srcview.aspx?dir=Tar&file=Tar.cs
There's a makefile to allow you to build Tar.dll or Tar.exe. There's also a sample app in VB.