Tar (on Windows) list of files in C #

Then I pass tar and then gzip the list of files in C #.

I need help on how to set the arguments to tar.

Let's say I have tar.exe in c: \ tar \ tar.exe folder 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 contains full paths to filenames, and files can be in different folders.

Can anyone help with what the arguments for the supply are.

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 put gzip.exe in the same folder as tar.exe , can I execute my tar and then gzip those files in one step ?

Update

I think I can get tar to work with files in the same directory as tar.exe if I try the full pathname. I am getting 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 using forward slashes \ and / and with quotes all the way around with no joy.

thank

+2


source to share


2 answers


to create an archive and gzip it you have to use czf as arguments, so

p.StartInfo.Arguments = "czf";

      

or

p.StartInfo.Arguments = "-czf";

      



depending on the tar version.

to avoid gzipping, remove the 'z' from the arguments.

ah and you are better off creating the whole folder, for example put your entire file in a folder named like my folder and tar, not in content.

+3


source


FYI, there is a managed tar library with full source available at http://cheeso.members.winisp.net/srcview.aspx?dir=Tar&file=Tar.cs



A makefile is provided that allows you to create Tar.dll or Tar.exe. There's also a sample application in VB.

0


source







All Articles