short (displayed) path and filename

  • Thread starter Thread starter Charles Conlow
  • Start date Start date
C

Charles Conlow

I'm certain there's a simple way to do this, but I just can't find the
pointers...

How to get the huge 'drive:\long\path\to get\there\filename.ext' to
something like 'D:\Docu...\filename.ext'

I searched through help files, but I must be missing something obvious. Any
help here?

Chuck
 
Charles Conlow said:
I'm certain there's a simple way to do this, but I just can't find the
pointers...

How to get the huge 'drive:\long\path\to get\there\filename.ext' to
something like 'D:\Docu...\filename.ext'

I simply did some string processing. If the string is above a certain
length, then take the first 10 characters, put in a "...", and the last 10
characters.
 
Thanks Michael... that's what I'm doing now. I THOUGHT I saw a function that
did this SOMWEHERE... I may be mistaken :-)

Chuck
 
Charles Conlow said:
Thanks Michael... that's what I'm doing now. I THOUGHT I saw a function that
did this SOMWEHERE... I may be mistaken :-)

It would be handy if they'd give us one that would compress a path to a
specified maximum number of characters, for display only.

I suppose I should do a systematic implementation of this myself, instead of
just the improvised one that I have now.
 
Search for the PathCompactPath ( or PathCompactPathEx) API functions.
Should be in Shlwapi.dll if i remember correctly.

-Rob Teixeira [MVP]
 
Hi all,

Such functionality does exist, but as a part of the Win32 API; therefore
interop is required. If you're using C#, as I assume you are since you
posted to this ng, then place the following pinvoke thunks in your code -


[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
public static extern int GetShortPathName(
[MarshalAs(UnmanagedType.LPTStr)]
System.String path,
[MarshalAs(UnmanagedType.LPTStr)]
System.Text.StringBuilder shortPath,
System.Int32 shortPathLength);

[DllImport("kernel32", CharSet = CharSet.Auto)]
public static extern int GetLongPathName(
[MarshalAs(UnmanagedType.LPTStr)]
System.String path,
[MarshalAs(UnmanagedType.LPTStr)]
System.Text.StringBuilder longPath,
System.Int32 longPathLength);

And then call them from your C# code. The StringBuilder object receives the
result. You can then convert DOS pathnames to Win32 pathnames and vice
versa.

HTH,
Ben
 
Doh!

I suppose it would have been nice had I more carefully read the question.

Ben

Ben Rush said:
Hi all,

Such functionality does exist, but as a part of the Win32 API; therefore
interop is required. If you're using C#, as I assume you are since you
posted to this ng, then place the following pinvoke thunks in your code -


[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
public static extern int GetShortPathName(
[MarshalAs(UnmanagedType.LPTStr)]
System.String path,
[MarshalAs(UnmanagedType.LPTStr)]
System.Text.StringBuilder shortPath,
System.Int32 shortPathLength);

[DllImport("kernel32", CharSet = CharSet.Auto)]
public static extern int GetLongPathName(
[MarshalAs(UnmanagedType.LPTStr)]
System.String path,
[MarshalAs(UnmanagedType.LPTStr)]
System.Text.StringBuilder longPath,
System.Int32 longPathLength);

And then call them from your C# code. The StringBuilder object receives the
result. You can then convert DOS pathnames to Win32 pathnames and vice
versa.

HTH,
Ben



in message news:eihWpuc%[email protected]...
function
that

It would be handy if they'd give us one that would compress a path to a
specified maximum number of characters, for display only.

I suppose I should do a systematic implementation of this myself,
instead
of
just the improvised one that I have now.
 
Back
Top