-
Aug 14th, 2003, 09:46 PM
#1
Thread Starter
Registered User
How to shorten the string of file path? [Resolved]
I add an OpenFileDialog to my project.
In order to identify the path of the file that I want to open, I added this code:
Code:
Dim strSourceFilename As String = OpenFileDialog.FileName
As a result, strSourceFilename will show the file path. For example:
C:\Documents and Settings\Tan\My Documents\Trainee\Payroll System\frmMain.vb
How can I shorten the file path to look something like this:
C:\Documents and Settings\.....\Payroll System\frmMain.vb
I just want the string in the middle part be replaced by ".....", while the front part and the end part (file name) remain unchanged.
How can I make it? please guide me. thank you.
Last edited by albertlse; Aug 21st, 2003 at 08:09 PM.
-
Aug 14th, 2003, 11:02 PM
#2
Use a regex statement to split the filename into an array by seperating them with \
Then take the first 2 or how many in the array, put them into a string with slashes(since regex took them out)
Then add in the dots (....) to the string
Then take the last item in the array and add it to the end of that string.
Hope that helps
-
Aug 15th, 2003, 04:02 AM
#3
Thread Starter
Registered User
thanx for replying.
is there anymore easier solutions?
-
Aug 15th, 2003, 09:54 AM
#4
There is an API that does exactly that, the only thing is I forgot which one. If you want to wait until Monday then I can get back to you with it. I have it at home but I just moved so I don't have internet access at home yet.
-
Aug 15th, 2003, 09:58 AM
#5
Wait I found it. Its either PathCompactPath or PathCompactPathEx.
-
Aug 15th, 2003, 08:34 PM
#6
Thread Starter
Registered User
Edneeis, thanx 4 ur reply.
i find the Path Functions only works in VB 4, 5 and 6. am i right? if yes, how can it works in VB.NET?
where can i get "shlwapi.dll"?
pls guide thank you.
-
Aug 18th, 2003, 09:49 AM
#7
No it works fine in .NET. What do you mean where do you find shlwapi.dll? You don't need to find it its an API call you just declare the function and actually for this particular function the declaration doesn't even change for .NET.
VB Code:
Private Declare Function PathCompactPathEx Lib "shlwapi.dll" Alias "PathCompactPathExA" (ByVal pszOut As String, ByVal pszSrc As String, ByVal cchMax As Long, ByVal dwFlags As Long) As Long
Private Declare Function PathCompactPath Lib "shlwapi.dll" Alias "PathCompactPathA" (ByVal hDC As Long, ByVal pszPath As String, ByVal dx As Long) As Long
Public Shared Function CompactEx(ByVal originalPath As String, ByVal maxChars As Long) As String
Dim buffer As New String(Char.Parse(0), 255)
PathCompactPathEx(buffer, originalPath, maxChars, 0)
Return buffer.TrimEnd
End Function
-
Aug 21st, 2003, 08:08 PM
#8
Thread Starter
Registered User
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|