474,064 Members | 1,418 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Trimming a path string


Hello.

I use the following line which returns the path of a file and adds it to
a listbox. How can I modify this line so that it only returns the
filename and not the entire path?
--> TxtAttachment.A ddItem (vrtSelectedIte m)
vrtSelectedItem is the variable which contains the path.

Thank you

Colin


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 13 '05 #1
7 2316
ColinWard <je*********@ho tmail.com> wrote in message news:<41******* *************** @news.newsgroup s.ws>...
Hello.

I use the following line which returns the path of a file and adds it to
a listbox. How can I modify this line so that it only returns the
filename and not the entire path?
--> TxtAttachment.A ddItem (vrtSelectedIte m)
vrtSelectedItem is the variable which contains the path.

Thank you

Colin

I'm sure there's an easier way, but here's one...

Option Compare Database
Option Explicit

Public Function PathOnly(ByVal strFileName As String) As String
Dim strTemp As String
strTemp = StrReverse(strF ileName)
strTemp = Left$(strTemp, InStr(1, strTemp, "\") - 1)
strTemp = StrReverse(strT emp)
PathOnly = strTemp
End Function
Nov 13 '05 #2
ColinWard <je*********@ho tmail.com> wrote in message news:<41******* *************** @news.newsgroup s.ws>...
Hello.

I use the following line which returns the path of a file and adds it to
a listbox. How can I modify this line so that it only returns the
filename and not the entire path?
--> TxtAttachment.A ddItem (vrtSelectedIte m)
vrtSelectedItem is the variable which contains the path.

Thank you

Colin


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


Colin,

Try
--> TxtAttachment.A ddItem (mid(vrtSelecte dItem,InStr(vrt SelectedItem,"\ ")+1))

HTH

Sunil Korah
Nov 13 '05 #3
Colin,

First, find the position of the last slash in the string, everything
after that is the filename:

Function GetFile(inPathF ile As String) As String

Dim iLastSlash As Integer

Do Until (InStr(iLastSla sh + 1, inPathFile, "\")) = 0
iLastSlash = InStr(iLastSlas h + 1, inPathFile, "\")
Loop

GetFile = Right(inPathFil e, Len(inPathFile) - iLastSlash)

End Function

Regards, GJ
ColinWard <je*********@ho tmail.com> wrote in message news:<41******* *************** @news.newsgroup s.ws>...
Hello.

I use the following line which returns the path of a file and adds it to
a listbox. How can I modify this line so that it only returns the
filename and not the entire path?
--> TxtAttachment.A ddItem (vrtSelectedIte m)
vrtSelectedItem is the variable which contains the path.

Thank you

Colin


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 13 '05 #4
Thank you guys.

I tried sunil's solution first because it looked simplest to implement.
Unfortunately, all it did was strip the drive letter off the path. I
then went to pieter's solution and it worked perfectly.

Thank you all

Colin

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 13 '05 #5
"Pieter Linden" <pi********@hot mail.com> wrote in message
news:bf******** *************** ***@posting.goo gle.com...
I'm sure there's an easier way, but here's one...

strTemp = StrReverse(strF ileName)


Gee, I was NOT aware of the "reverse" function, and thus your solton is
cute!!

However, do note that we have

InstrRev, which is simply Instr, but it stards at the rigth side...

So...

FileNameOnly = mid$(strFileNam e , InStrRev(strFil eName, "\") + 1)

--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
pl************* ****@msn.com
http://www.attcanada.net/~kallal.msn
Nov 13 '05 #6
"Albert D. Kallal" <Pl************ *******@msn.com > wrote in message news:<TdI2d.454 703$gE.238453@p d7tw3no>...
"Pieter Linden" <pi********@hot mail.com> wrote in message
news:bf******** *************** ***@posting.goo gle.com...

I'm sure there's an easier way, but here's one...

strTemp = StrReverse(strF ileName)


Gee, I was NOT aware of the "reverse" function, and thus your solton is
cute!!

However, do note that we have

InstrRev, which is simply Instr, but it stards at the rigth side...

So...

FileNameOnly = mid$(strFileNam e , InStrRev(strFil eName, "\") + 1)

See, I TOLD YA there had to be an easier way!!! Thanks Albert!
Nov 13 '05 #7
"Pieter Linden" <pi********@hot mail.com> wrote in message
news:bf******** *************** **@posting.goog le.com...

See, I TOLD YA there had to be an easier way!!! Thanks Albert!


You are welcome. Fact is...we both learned some new things here..and that is
a great part of helping out in newsgroups...
--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
pl************* ****@msn.com
http://www.attcanada.net/~kallal.msn
Nov 13 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
4841
by: Generic Usenet Account | last post by:
I have worked out the following implementation for trimming the leading and trailing whitespace characters of a string (I am surprised not to see these as member functions). Am I doing it correctly, or is there a better way to do it? Thanks, Gus //////////// Source code begin /////////////////////
13
3694
by: john_g83 | last post by:
have a bit of c code that is ment to take a string (that may or may not have spaces before or after the string) i.e. " stuff ", and trims off the whitespace before and after. Code: char *trim (char *str, char ch) { char *first, *last; int count;
4
1198
by: Chris | last post by:
Hi, I have the follwing url http://localhost/testsite/test/webform1.aspx?cat=dog Is there a function available in the request.url object to return only the webform1.aspx or even /webform1.aspx? Thanks
0
1222
by: Paul | last post by:
On my local site, I have a folder that is security trimmed, so that only members of a Role can see it after they register and log on (I set the memberships). All works fine locally. However, when I deployed to my ISP, the security trimming does not work. Here is the relevant code. I can add users just fine, they show up in the ISP SQL Server database, and I can log on and off.
8
2834
by: PvtPile | last post by:
I've got a form where i need to pull both the directory of a filename and the directory with the filename of an .inf file... I figured the easiest way to do this was to have an <input id=test type=file runat=server> control for the user to find the .inf file, and then make vb cut off the filename upon submission of the form. I just can't figure out how to trim off the filename leaving just the directory it's located in. just as a test...
3
1964
by: Enyi | last post by:
Situation : Need to get a list of files in a directory, but I am currently getting the whole path of the file (Example: "C:\A Folder\Another Folder\file.txt"). What I want is just the filename and extension. So from above example, all I actually want is "file.txt". Language: VB.NET 2005 Current Code: Imports System.Collections.ObjectModel ... Dim files As ReadOnlyCollection(Of String)
1
1055
by: saldelmundo | last post by:
I'm a rookie with vb.net and I'm trying to modify source code that was given to me... in short the program I have is a file copy application... it reads a file name and path from a given txt file and it does a dlg_open on that file to get the string necessary... however if that file contains a carriage return at the end, I get an error saying there are illegal characters in the path... I would like it to ignore any CRs obviously. The code...
1
2406
livid86
by: livid86 | last post by:
Hey, I am trying to setup my application so only users with particular roles can see navigation items that match there role. (such as admin can see the admin navigation items) Well my problem is it's not working and i have checked several sites and found nothing. If anyone could help i would really appreciate it. This is my code for my Web.Sitemap <?xml version="1.0" encoding="utf-8" ?> <siteMap...
5
1511
by: vinod allapu | last post by:
Hi all I have a string like this "2/6/1986" which is a date..Remember that it is a date actually..so day size and month size are variant..It is not always single digit or single character... I want "1986","6","2" individually... Can anybody provide trimming code to do this .. Thankful to you all,
0
10404
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
12239
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
12161
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
11188
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
7928
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
6722
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
6920
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4984
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
4034
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.