473,809 Members | 2,649 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

String Handling: Truncating Long Path Names

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\233424 32sss\2343243cc c\32432432423ee ee\2432424cc\t
tt\xxx\tttt\xxx \explorer.exe-ph33334

into something like:

c:\winnt\...\ex plorer.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
3 2435
* "Ron" <an*******@disc ussions.microso ft.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\233424 32sss\2343243cc c\32432432423ee ee\2432424cc\t
tt\xxx\tttt\xxx \explorer.exe-ph33334

into something like:

c:\winnt\...\ex plorer.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.dl l" Alias "PathCompactPat hA" ( _
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(strFileP ath)
ReleaseDC(Me.Ha ndle, hDC)
End Sub
///

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #2
> I want to take the following string:

c:\winnt\233424 32sss\2343243cc c\32432432423ee ee\2432424cc\t
tt\xxx\tttt\xxx \explorer.exe-ph33334

into something like:

c:\winnt\...\ex plorer.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.LastInde xOf. 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
Ron,
In addition to Herfried's suggestion of PathCompactPath , there is
PathCompactPath Ex that accepts a length instead of a HDC.

Something like:
Declare Auto Function PathCompactPath Ex Lib "shlwapi.dl l" (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\23342 432sss\2343243c cc\32432432423e eee\2432424cc\t tt\xxx\tttt\xxx \
explorer.exe-ph33334"
stringOut = New String(" "c, 34)
PathCompactPath Ex(stringOut, stringIn, stringOut.Lengt h, 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*******@disc ussions.microso ft.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\233424 32sss\2343243cc c\32432432423ee ee\2432424cc\t
tt\xxx\tttt\xxx \explorer.exe-ph33334

into something like:

c:\winnt\...\ex plorer.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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2063
by: R.G. Vervoort | last post by:
Does anyone have a suggestion how I can order a list with names in a secondary select string. The first string selects a number of locations where people work From this string I get several id's form people (in the location table there
37
8551
by: Shri | last post by:
hi all, i am writing a code in which i have a char buffer "cwdir" which hold the current working directory by calling the function getcwd(). later i change the directory to "/" as i have to make my code Deamon. and later again i want to run some other executable available at the path holded by the "cwdir" using the system() system call. presently i concatenate program name (to be executed) to the "cwdir" and use system(chdir)to run the...
7
5593
by: techno | last post by:
Dear all, Our bitmap has some x00 values ( '\0' ) and i am storing it in char* array. the problem is that the '\0' is treated as eos character in c and it is truncating it so the characters after it are not pass to the function. here is the code snippet /* DATA8583.data = ( char ) ( unsigned int ) 0xF0;
5
3895
by: raffelm | last post by:
I'm struggling to find a way to include long path names in a command line argument string that I have to build at runtime. I need to create a string like -o:"c:\my documents\my file.txt". Everything I have tried so far causes the program I am calling to fail (I know it can accept long file names as I have tried it from the cmdline). The problem I am having is using the Format command and getting "
3
2264
by: rangermccoy | last post by:
Hello there, What are the best php/c libraries for handling media including images, video, and music? I would like to manipulate media dfiles, including watermarking, thumbnailing, truncating, etc. I know there's the GD llibrary for images.
7
7821
by: Sky | last post by:
I have been looking for a more powerful version of GetType(string) that will find the Type no matter what, and will work even if only supplied "{TypeName}", not the full "{TypeName},{AssemblyName}" As far as I know yet -- hence this question -- there is no 'one solution fits all', but instead there are several parts that have to be put together to check. What I have so far is, and would like as much feedback as possible to ensure I've...
2
2291
by: Stimp | last post by:
Hi all, Having a bit of a headache trying to do this. I want to create a string with a total length of 160 characters. The first few characters must always be in the string.. say around 45 characters. After this I want to append another string, description, which can be
5
10045
by: =?Utf-8?B?SmVmZiBCZWVt?= | last post by:
Before you respond with "just use GetShortPathName" please read the rest. We have an application that places files on a file server using mapped drives as it's path of choice. The reason for this is because using a UNC paths makes the path longer, causing the periodic problem with a path that is too long (over 260 chars). We also have an asp.net app that needs to access those files. Accessing mapped drives from an IIS application is...
1
1233
by: David C | last post by:
I have an asp.net VB application that gets a filename and tries to display it on a web page. It seems to be truncating the name when the name contains "&" in it. Below is what I am using to grab the name. How can I get around that? Thanks. David If Not Request.Cookies("path") Is Nothing Then strPath = Server.HtmlEncode(Request.Cookies("path").Value) strPath = Request.Cookies("path").Value End If
0
10378
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10391
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10121
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9200
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7664
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6881
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5690
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3862
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.