Solved

Extract filename from full path

Posted on 2013-11-01
3
435 Views
Last Modified: 2013-11-01
Hi guys

The following code will extract the filename of a fully qualified path

sFullPath = "C:\dir\dir\dir\file.txt"
extractFileName = mid(pathStr,instrRev(sFullPath ,"\")+1)

extractfilename will be file.txt

This code will just return the filename without extension - ie "file"

sFullPath = "C:\dir\dir\dir\file.txt"  
sFullFilename = Right(sFullPath, Len(sFullPath) - InStrRev(sFullPath, "\"))
sFilename = Left(sFullFilename, (InStr(sFullFilename, ".") - 1))

But it is not full proof, it does not take into consideration files that contain more than 2 decimals eg. *.tar.gz

How can I cater for that ? I need to return just the filename without the path, no matter how many dots there are in the filename.

MTIA

DWE
0
Comment
Question by:dwe0608
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 75

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 250 total points
ID: 39617912
Use InStrRev instead of InStr on the search for the dot.
0
 
LVL 33

Accepted Solution

by:
Big Monty earned 250 total points
ID: 39617928
to further explain the answer above:

change

sFilename = Left(sFullFilename, (InStr(sFullFilename, ".") - 1))

to

sFilename = Left(sFullFilename, (InStrRev(sFullFilename, ".") - 1))
0
 
LVL 1

Author Closing Comment

by:dwe0608
ID: 39617943
thanks greatly - seems to work a treat :-)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Multiflying 2 Input Text On a Table 7 32
Session on Html 8 39
JS to redirect to prev page 8 20
JQuery DataTable Functionality 8 15
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question