dir /ad/x
PathConverter.GetShortPathNames
using System; using System.Linq; using System.Runtime.InteropServices; using System.Text; namespace ShortPathConverter { internal class PathConverter { public static String GetShortPathName(String longPath) { StringBuilder shortPath = new StringBuilder(longPath.Length + 1); if (0 == PathConverter.GetShortPathName(longPath, shortPath, shortPath.Capacity)) { return longPath; } return shortPath.ToString(); } // This method can shorten your PATH environment variable public static String GetShortPathNames(String longPathNames, String delimiter = ";") { var items = longPathNames.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); var longPaths = items.Select(o => o.ToLowerInvariant()) .Distinct() .Select(o => PathConverter.GetShortPathName(o)) .ToList(); return string.Join(";", longPaths); } [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)] private static extern Int32 GetShortPathName(String path, StringBuilder shortPath, Int32 shortPathLength); } }
ScrewTurn Wiki version 3.0.1.400. Some of the icons created by FamFamFam. Except where noted, all contents Copyright © 1999-2024, Patrick Jasinski.