rulururu

post Long Pathes

March 25th, 2008

Filed under: .NET, Windows — Kai @ 2:10 am

Just a short snipped I’d like to not forget about.

The maximal possible pathlength on Windows is, as you probably know, 255 chars. For that reason you can use the following:

Convert short path to long:

String s = Short2Long(@"D:\MYTEMP~1\RESOUR~1\sql.txt");
 
public static String Short2Long(String sShortPath) {
    StringBuilder sLongPath = new StringBuilder(255);
    GetLongPathName(sShortPath, sLongPath, sLongPath.Capacity);
    return sLongPath.ToString();
}

Vice versa:

String s = Long2Short(@"D:\My Temp\ResourseProvider\sql.txt");
 
public static String Long2Short(String sLongPath) {
    StringBuilder sShortPath = new StringBuilder(255);
    GetShortPathName(sLongPath, sShortPath, sShortPath.Capacity);
    return sShortPath.ToString();
}

Hope it might help you somewhere along the way ;)

1 Comment »

  1. Your fonts are very small — hard to read.

    Comment by Andreas Brekken — September 16, 2008 @ 3:13 pm

RSS feed for comments on this post. TrackBack URI

Leave a comment

ruldrurd
Powered by WordPress, Content and Design by Kai Bellmann
Entries (RSS) and Comments (RSS)