473,323 Members | 1,550 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

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.AddItem (vrtSelectedItem)
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 2287
ColinWard <je*********@hotmail.com> wrote in message news:<41**********************@news.newsgroups.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.AddItem (vrtSelectedItem)
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(strFileName)
strTemp = Left$(strTemp, InStr(1, strTemp, "\") - 1)
strTemp = StrReverse(strTemp)
PathOnly = strTemp
End Function
Nov 13 '05 #2
ColinWard <je*********@hotmail.com> wrote in message news:<41**********************@news.newsgroups.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.AddItem (vrtSelectedItem)
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.AddItem (mid(vrtSelectedItem,InStr(vrtSelectedItem,"\")+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(inPathFile As String) As String

Dim iLastSlash As Integer

Do Until (InStr(iLastSlash + 1, inPathFile, "\")) = 0
iLastSlash = InStr(iLastSlash + 1, inPathFile, "\")
Loop

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

End Function

Regards, GJ
ColinWard <je*********@hotmail.com> wrote in message news:<41**********************@news.newsgroups.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.AddItem (vrtSelectedItem)
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********@hotmail.com> wrote in message
news:bf**************************@posting.google.c om...
I'm sure there's an easier way, but here's one...

strTemp = StrReverse(strFileName)


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$(strFileName , InStrRev(strFileName, "\") + 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.454703$gE.238453@pd7tw3no>...
"Pieter Linden" <pi********@hotmail.com> wrote in message
news:bf**************************@posting.google.c om...

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

strTemp = StrReverse(strFileName)


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$(strFileName , InStrRev(strFileName, "\") + 1)

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

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
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...
13
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...
4
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...
0
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,...
8
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...
3
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...
1
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...
1
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...
5
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.