2016-10-28 01:46:43 +00:00
|
|
|
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
|
|
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
|
|
namespace Microsoft.DotNet.TestFramework
|
|
|
|
{
|
|
|
|
internal static class DirectoryInfoExtensions
|
|
|
|
{
|
2023-11-11 01:08:10 +00:00
|
|
|
public static bool Contains(this DirectoryInfo subject, FileSystemInfo target) => target.FullName.StartsWith(subject.FullName);
|
2016-10-28 01:46:43 +00:00
|
|
|
|
2023-11-11 01:08:10 +00:00
|
|
|
public static DirectoryInfo GetDirectory(this DirectoryInfo subject, params string[] directoryNames) => new DirectoryInfo(Path.Combine(subject.FullName, Path.Combine(directoryNames)));
|
2016-10-28 01:46:43 +00:00
|
|
|
|
2023-11-11 01:08:10 +00:00
|
|
|
public static FileInfo GetFile(this DirectoryInfo subject, string fileName) => new FileInfo(Path.Combine(subject.FullName, fileName));
|
2017-01-06 09:40:26 +00:00
|
|
|
|
|
|
|
public static void EnsureExistsAndEmpty(this DirectoryInfo subject)
|
|
|
|
{
|
|
|
|
if (subject.Exists)
|
|
|
|
{
|
|
|
|
subject.Delete(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
subject.Create();
|
|
|
|
}
|
2016-10-28 01:46:43 +00:00
|
|
|
}
|
|
|
|
}
|