[DllImport("shell32.dll", EntryPoint="PathCleanupSpec", CharSet=CharSet.Unicode)]
internal static extern int PathCleanupSpec(
StringBuilder pszDir,
[MarshalAs(UnmanagedType.LPWStr)]StringBuilder pszSpec);
<DllImport("shell32.dll", EntryPoint:="PathCleanupSpec", CharSet:=CharSet.Unicode)> _
Friend Shared Function PathCleanupSpec( _
ByVal pszDir As StringBuilder, _
<MarshalAs(UnmanagedType.LPWStr)> ByVal pszSpec As StringBuilder) As Integer
End Function
const int MAX_PATH = 260;
StringBuilder folderSpec = new StringBuilder(MAX_PATH);
folderSpec.Append(@"D:\");
StringBuilder fileSpec = new StringBuilder(MAX_PATH);
fileSpec.Append("Bad*file?<test>.txt");
int result = NativeMethods.PathCleanupSpec(folderSpec, fileSpec);
Console.WriteLine("FileName: {0}", fileSpec.ToString());