Need filename only not location

  • Thread starter Thread starter bballpinhead
  • Start date Start date
B

bballpinhead

I have figured out how to locate a file and bring it into a text box.
But now I need to only get the filename out of that text box not the
whole location. Example: "D:\Documents and Settings\My Documents\I Many
Stuff\Defaults.xls" out of this I only need the word "Defaults" I know
there is a way I just can't find it.
 
Use InStrRev() to locate the last "\", and Right() to grab the last four
characters to make sure they are ".xls" before using Mid() to return the
substring between the position of the "\" and the ".".
 
strWholePath = "D:\Documents and Settings\My Documents\I Many
Stuff\Defaults.xls"

strNameOnly = Right(strWholePath, Len(strWholePath) - InStrRev(strWholePath,
"\"))

strNameOnly = Left(strNameOnly, InStr(strNameOnly, ".") - 1)
 
strNameOnly = Left(strNameOnly, InStr(strNameOnly, ".") - 1)

It might be safer to allow for periods in the file name, e.g.
My Workbook 26.05.06 version 1.xls
as well as for files with no extension. Maybe this:

If InStr(strNameOnly, ".") Then
strNameOnly = Left(strNameOnly, InStrRev(strNameOnly) - 1)
End If
 
Uzytkownik "bballpinhead said:
I have figured out how to locate a file and bring it into a text box.
But now I need to only get the filename out of that text box not the
whole location. Example: "D:\Documents and Settings\My Documents\I Many
Stuff\Defaults.xls" out of this I only need the word "Defaults" I know
there is a way I just can't find it.

===========================================================================
FULL LEGAL SOFTWARE !!!
Games, video, program, image, chat, questbook, catalog site, arts, news,
and...
This site it is full register and legal software !!!
Please download and you must register software !!!

PLEASE REGISTER SOFTWARE:
http://www.webteam.gsi.pl/rejestracja.htm
DOWNLOAD LEGAL SOFTWARE:
http://www.webteam.gsi.pl

Full question and post: http://www.webteam.gsi.pl

Contact and service and advanced technology:
http://www.webteam.gsi.pl/kontakt.htm
FAQ: http://www.webteam.gsi.pl/naj_czesciej_zadawane_pytania.htm

Please add me URL for you all site and search engines and best friends !!!

Me site:
SERWIS WEBNETI: http://www.webneti.gsi.pl
PORTAL WEBTEAM:http://www.webteam.gsi.pl
LANGUAGE: http://www.webneti.cjb.net

==========================================================================
 
Back
Top