Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Extract filename from full path

Posted on 2013-11-01
3
Medium Priority
?
443 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
3 Comments
 
LVL 75

Assisted Solution

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

Accepted Solution

by:
Big Monty earned 1000 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

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…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

772 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