本文整理汇总了C#中DirectoryInfo.Equals方法的典型用法代码示例。如果您正苦于以下问题:C# DirectoryInfo.Equals方法的具体用法?C# DirectoryInfo.Equals怎么用?C# DirectoryInfo.Equals使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DirectoryInfo
的用法示例。
在下文中一共展示了DirectoryInfo.Equals方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Unpack
/// <summary>
/// Unzips the selected files from the zip stream onto the target directory.
/// </summary>
/// <param name="zipStream" this="true">The stream to unpack</param>
/// <param name="targetDir">The target directory where stream will be unpacked</param>
/// <param name="filesToUnpack">The files to be unpacked</param>
/// <remarks>
/// If the <paramref name="targetDir"/> already exists,
/// it's deleted before unzipping begins to ensure a
/// clean destination folder.
/// <para>
/// The compressed stream must be a proper Package in term of XPS/OPC
/// (at a minimum, have a [Content_Types].xml).
/// </para>
/// </remarks>
/// <example>
/// <code>
/// using (var pkg = File.OpenRead("netfx-Guard.1.2.0.0.nupkg"))
/// {
/// pkg.Unpack("TempDir", "Guard.cs");
/// }
/// </code>
/// </example>
public static void Unpack(this Stream zipStream, string targetDir, params string[] filesToUnpack)
{
var baseDir = new DirectoryInfo(Environment.ExpandEnvironmentVariables(targetDir));
if (!baseDir.Exists)
{
baseDir.Create();
}
else
{
baseDir.Delete(true);
baseDir.Create();
}
using (var package = ZipPackage.Open(zipStream, FileMode.Open, FileAccess.Read))
{
foreach (var part in package.GetParts())
{
var targetFile = BuildTargetFileName(baseDir.FullName, part.Uri);
if (ShouldUnpack(targetFile, filesToUnpack))
{
var dirName = Path.GetDirectoryName(Environment.ExpandEnvironmentVariables(targetFile));
if (!baseDir.Equals(dirName))
{
var subDir = new DirectoryInfo(dirName);
if (!subDir.Exists)
{
subDir.Create();
}
}
using (var partStream = part.GetStream())
{
partStream.WriteTo(targetFile);
}
}
}
}
}