Solved

Extract filename from full path

Posted on 2013-11-01
3
433 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 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

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Suggested Solutions

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/…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

777 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