By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,949 Members | 1,511 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,949 IT Pros & Developers. It's quick & easy.

String Handling: Truncating Long Path Names

P: n/a
Ron
I *just* know there's a function to do this, but I can't
find it:

I want to take the following string:

c:\winnt\23342432sss\2343243ccc\32432432423eeee\24 32424cc\t
tt\xxx\tttt\xxx\explorer.exe-ph33334

into something like:

c:\winnt\...\explorer.exe-ph33334

Is there a function to do this?

And a related question:

Is there a 64 char limit to the NotifyIcon text? If so,
can I override it?

Thanks.

RON
Nov 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
* "Ron" <an*******@discussions.microsoft.com> scripsit:
I *just* know there's a function to do this, but I can't
find it:

I want to take the following string:

c:\winnt\23342432sss\2343243ccc\32432432423eeee\24 32424cc\t
tt\xxx\tttt\xxx\explorer.exe-ph33334

into something like:

c:\winnt\...\explorer.exe-ph33334

Is there a function to do this?


\\\
Private Declare Function GetWindowDC Lib "user32.dll" ( _
ByVal hwnd As IntPtr _
) As IntPtr

Private Declare Function ReleaseDC Lib "user32.dll" ( _
ByVal hwnd As IntPtr, _
ByVal hdc As IntPtr _
) As IntPtr

Private Declare Function PathCompactPath Lib "shlwapi.dll" Alias "PathCompactPathA" ( _
ByVal hDC As IntPtr, _
ByVal lpszPath As String, _
ByVal dx As Int32 _
) As Int32

Private Sub Test()
Dim hDC As IntPtr = GetWindowDC(Me.Handle)
Dim strFilePath As String = _
"C:\Program Files\Some Company\Some Product\bla\bla\File.txt"
PathCompactPath(hDC, strFilePath, 250)
MsgBox(strFilePath)
ReleaseDC(Me.Handle, hDC)
End Sub
///

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #2

P: n/a
> I want to take the following string:

c:\winnt\23342432sss\2343243ccc\32432432423eeee\24 32424cc\t
tt\xxx\tttt\xxx\explorer.exe-ph33334

into something like:

c:\winnt\...\explorer.exe-ph33334

Is there a function to do this?
You need to look for the position of the second and the last "\", create
substrings and concatenate them. Use InStr/InStrRev or
String.IndexOf/String.LastIndexOf. Watch out for the exceptions (ie. file in
root directory).
And a related question:

Is there a 64 char limit to the NotifyIcon text? If so,
can I override it?


ToolTip text must be less than 64 characters long.
http://msdn.microsoft.com/library/de...stexttopic.asp

Always look in MSDN for answers to your questions.

sincerely,
--
Sebastian Zaklada
Skilled Software
http://www.skilledsoftware.com
************************************
SQL Source Control 2003 - for
SQL Server Source Safe integration
and custom databases documentation
Nov 20 '05 #3

P: n/a
Ron,
In addition to Herfried's suggestion of PathCompactPath, there is
PathCompactPathEx that accepts a length instead of a HDC.

Something like:
Declare Auto Function PathCompactPathEx Lib "shlwapi.dll" (ByVal pszOut
As String, ByVal pszSrc As String, ByVal cchMax As Integer, ByVal dwFlags As
Integer) As Boolean

Public Shared Sub Main()
Dim stringIn As String
Dim stringOut As String
stringIn =
"c:\winnt\23342432sss\2343243ccc\32432432423eeee\2 432424cc\ttt\xxx\tttt\xxx\
explorer.exe-ph33334"
stringOut = New String(" "c, 34)
PathCompactPathEx(stringOut, stringIn, stringOut.Length, 0)
stringOut = stringOut.Trim(ChrW(0)) ' remove trailing null char
Debug.WriteLine(stringIn, "String in")
Debug.WriteLine(stringOut, "String out")
End Sub

Hope this helps
Jay

"Ron" <an*******@discussions.microsoft.com> wrote in message
news:6c****************************@phx.gbl...
I *just* know there's a function to do this, but I can't
find it:

I want to take the following string:

c:\winnt\23342432sss\2343243ccc\32432432423eeee\24 32424cc\t
tt\xxx\tttt\xxx\explorer.exe-ph33334

into something like:

c:\winnt\...\explorer.exe-ph33334

Is there a function to do this?

And a related question:

Is there a 64 char limit to the NotifyIcon text? If so,
can I override it?

Thanks.

RON

Nov 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.