DotNetZip 在哪里获取它的根目录以进行保存。所有保存示例都不显示目录。
我的目标是递归文件夹和子文件夹。在每个文件夹中,我想将所有文件压缩到一个 zip 中并删除源文件。
private void CopyFolder(string srcPath, string dstPath)
{
if (!Directory.Exists(dstPath))
Directory.CreateDirectory(dstPath);
string[] files = Directory.GetFiles(srcPath);
string msg;
string zipFileName;
using (ZipFile z = new ZipFile(Path.Combine(srcPath,String.Format("Archive{0:yyyyMMdd}.zip", DateTime.Now))))
{
z.ReadProgress += new EventHandler<ReadProgressEventArgs>(z_ReadProgress);
foreach (string file in files)
{
FileInfo fi = new FileInfo(file);
AddLog(String.Format("Adding {0}", file));
z.AddFile(file);
}
//z.Save(Path.Combine(srcPath, String.Format("Archive{0:yyyyMMdd}.zip", DateTime.Now)));
z.Save();
if (deleteSource)
{
foreach (string file in files)
{
File.Delete(file);
}
}
zipFileName = z.Name;
}
if (!compressOnly)
File.Copy(Path.Combine(srcPath,zipFileName), Path.Combine(dstPath, Path.GetFileName(zipFileName)));
string[] folders = Directory.GetDirectories(sourcePath);
foreach (string folder in folders)
{
string name = Path.GetFileName(folder);
string dest = Path.Combine(dstPath, name);
Console.WriteLine(ln);
log.Add(ln);
msg = String.Format("{3}{4}Start Copy: {0}{4}Directory: {1}{4}To: {2}", DateTime.Now.ToString("G"), name, dest, ln, Environment.NewLine);
AddLog(msg);
if (recurseFolders)
CopyFolder(folder, dest);
msg = String.Format("Copied Directory: {0}{4}To: {1}\nAt: {2}{3}", folder, dest, DateTime.Now.ToString("G"), Environment.NewLine);
AddLog(msg);
}
}