The following piece of code should turn the folder IN and its subfolders
into a single tar file
located in the folder OUT:
using ICSharpCode.SharpZipLib;
using ICSharpCode.SharpZipLib.Tar;
public static void Create_Tar_Archive(string IN,string OUT)
{
//IN and OUT are directories
if (IN=="" || OUT=="" || !System.IO.Directory.Exists(IN)
|| !System.IO.Directory.Exists(OUT)) return;
string OutName=OUT+"\\"+System.IO.Path.GetFileName(IN)+". tar";
Stream stmout=new FileStream(OutName,FileMode.OpenOrCreate);
TarArchive
TA=ICSharpCode.SharpZipLib.Tar.TarArchive.CreateOu tputTarArchive(stmout);
TarEntry TE=TarEntry.CreateEntryFromFile(IN);
TA.WriteEntry(TE,true);
TA.CloseArchive();
stmout.Close();
}
The code seems to work but inside the output tar archive the file paths are
absolute and not relative (they start with C:\...),
and so any attemp to "decompress" the archive into a target folder fails
(illegal paths).
I would like to know how to create a tar archive with relative file paths,
i.e. with a root directory named like System.IO.Path.GetFileName(IN) and the
relative subfolders inside it,
or simply with the files and subfolders of the directory IN in first place
with relative paths.
I don't know how to create the TarEntries to achieve that (the documentation
is not so clear).
Code or links are welcome. Thank you in advance.