PathCleanupSpec (shell32)
Last changed: -208.242.212.159

.
Summary
Removes illegal characters from a file or directory name. Enforces the 8.3 filename format on drives that do not support long file names.

C# Signature:

[DllImport("shell32.dll", EntryPoint="PathCleanupSpec", CharSet=CharSet.Unicode)]
internal static extern int PathCleanupSpec(
    StringBuilder pszDir,
    [MarshalAs(UnmanagedType.LPWStr)]StringBuilder pszSpec);

VB Signature:

<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

Sample Code:

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());

Documentation