Skip to content

Commit

Permalink
添加 includeBaseDirectory 参数到 Compress 方法
Browse files Browse the repository at this point in the history
增加了一个名为 `includeBaseDirectory` 的参数到 `Compress` 方法中。
修改了 `ZipFile.CreateFromDirectory` 方法的调用,将 `includeBaseDirectory` 参数传递给它,以控制是否在压缩文件中包含基础目录。
  • Loading branch information
猿人易 committed Nov 6, 2024
1 parent d21efc5 commit 8676c14
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions NewLife.Core/IO/PathHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -531,14 +531,15 @@ public static String[] CopyIfNewer(this DirectoryInfo di, String[] source, Strin
/// <summary>压缩</summary>
/// <param name="di"></param>
/// <param name="destFile"></param>
public static void Compress(this DirectoryInfo di, String? destFile = null)
/// <param name="includeBaseDirectory"></param>
public static void Compress(this DirectoryInfo di, String? destFile = null, Boolean includeBaseDirectory = true)
{
if (destFile.IsNullOrEmpty()) destFile = di.Name + ".zip";

if (File.Exists(destFile)) File.Delete(destFile);

if (destFile.EndsWithIgnoreCase(".zip"))
ZipFile.CreateFromDirectory(di.FullName, destFile, CompressionLevel.Optimal, true);
ZipFile.CreateFromDirectory(di.FullName, destFile, CompressionLevel.Optimal, includeBaseDirectory);
else
//new SevenZip().Compress(di.FullName, destFile);
throw new NotSupportedException();
Expand Down

0 comments on commit 8676c14

Please sign in to comment.