2016-01-07 08:17:16 -05:00
|
|
|
|
// Copyright 1998-2016 Epic Games, Inc. All Rights Reserved.
|
2015-06-01 10:14:54 -04:00
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Tools.DotNETCommon.FileSystem
|
|
|
|
|
|
{
|
|
|
|
|
|
public static class FileSystem
|
|
|
|
|
|
{
|
2015-07-27 12:09:13 -04:00
|
|
|
|
[DllImport("kernel32.dll", SetLastError=true, CharSet=CharSet.Unicode)]
|
2015-06-01 10:14:54 -04:00
|
|
|
|
private static extern int GetShortPathName(string pathName, StringBuilder shortName, int cbShortName);
|
|
|
|
|
|
|
|
|
|
|
|
public static string GetShortPathName(string Path)
|
|
|
|
|
|
{
|
|
|
|
|
|
int BufferSize = GetShortPathName(Path, null, 0);
|
|
|
|
|
|
if (BufferSize == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new Exception(string.Format("Unable to convert path {0} to 8.3 format", Path));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var Builder = new StringBuilder(BufferSize);
|
|
|
|
|
|
int ConversionResult = GetShortPathName(Path, Builder, BufferSize);
|
|
|
|
|
|
if (ConversionResult == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new Exception(string.Format("Unable to convert path {0} to 8.3 format", Path));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return Builder.ToString();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|