Files
UnrealEngineUWP/Engine/Source/Programs/DotNETCommon/DotNETUtilities/DirectoryUtils.cs
Ryan Durand 9ef3748747 Updating copyrights for Engine Programs.
#rnx
#rb none
#jira none

#ROBOMERGE-OWNER: ryan.durand
#ROBOMERGE-AUTHOR: ryan.durand
#ROBOMERGE-SOURCE: CL 10869242 in //Fortnite/Release-12.00/... via CL 10869536
#ROBOMERGE-BOT: FORTNITE (Main -> Dev-EngineMerge) (v613-10869866)

[CL 10870955 by Ryan Durand in Main branch]
2019-12-26 23:01:54 -05:00

52 lines
1.3 KiB
C#

// Copyright Epic Games, Inc. All Rights Reserved.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Tools.DotNETCommon
{
/// <summary>
/// Utility functions for manipulating directories
/// </summary>
public class DirectoryUtils
{
/// <summary>
/// Finds the on-disk case of a a directory
/// </summary>
/// <param name="Info">DirectoryInfo instance describing the directory</param>
/// <returns>New DirectoryInfo instance that represents the directory with the correct case</returns>
public static DirectoryInfo FindCorrectCase(DirectoryInfo Info)
{
DirectoryInfo ParentInfo = Info.Parent;
if (ParentInfo == null)
{
string FullName = Info.FullName;
if (FullName.Length >= 2 && (FullName[0] >= 'a' && FullName[0] <= 'z') && FullName[1] == ':')
{
return new DirectoryInfo(Char.ToUpper(FullName[0]) + FullName.Substring(1));
}
else
{
return Info;
}
}
else
{
ParentInfo = FindCorrectCase(ParentInfo);
foreach (DirectoryInfo ChildInfo in ParentInfo.EnumerateDirectories())
{
if (String.Equals(ChildInfo.Name, Info.Name, DirectoryReference.Comparison))
{
return ChildInfo;
}
}
return new DirectoryInfo(Path.Combine(ParentInfo.FullName, Info.Name));
}
}
}
}