Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trim a variable

Status
Not open for further replies.

Nebooaw

Programmer
Jun 1, 2001
142
GB
Hi, i have various variables like;

c:\images\photos\background.bmp
c:\images\temp.bmp

How can i trim everything away and just leave the name of the file and its extension?

ie;

background.bmp

Kind Thanks.
 

str = "c:\images\photos\background.bmp"
lastSlash = instrRev(str, "\")

str = mid(str,lastSlash + 1) Get the Best Answers! faq333-2924
Is this an asp FAQ? faq333-3048
Tek-Tips Best Practices: FAQ183-3179
It's sad that some Americans proudly turn their backs on the very Flag the gives them the opportunity to do just that... - Mike
 
Or another way:

Code:
Dim SomeFileSpec, fso
Set fso = CreateObject("Scripting.FileSystemObject")

SomeFileSpec = "\\Somewhere\c$\Inetpub\DischargeSummary\QueryPage.asp"

MsgBox fso.GetParentFolderName(SomeFileSpec)
MsgBox fso.GetBaseName(SomeFileSpec)
MsgBox fso.GetExtensionName(SomeFileSpec)
MsgBox fso.GetFileName(SomeFileSpec)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top