filesToInclude列表包含以下数据:
c:/temp/folder1/data.1
c:/temp/folder1/subfolder/data.1
c:/temp/folder1/subfolder2/data.1
以下DotNetZip代码存储以/ temp /开头的整个路径,但我喜欢只存储/ folder1 / without / temp /前缀。
using (ZipFile zip = new ZipFile())
{
foreach (var f in filesToInclude)
{
zip.AddFile(f);
}
答案 0 :(得分:1)
只需将目录部分指定为第二个参数即可。这意味着从完整文件名中查找目录,然后将前导部分剥离。
String baseDirectory = "c:/temp/";
using (ZipFile zip = new ZipFile())
{
foreach (var f in filesToInclude)
{
String directory = Path.GetDirectoryName(f);
// Consider adding error checking here to make sure that
// directory really does start with baseDirectory!
String relative = directory.Substring(baseDirectory.Length);
zip.AddFile(f, relative);
}
}