Solved

Extract filename from full path

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

Assisted Solution

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

Accepted Solution

by:
Big Monty earned 250 total points
Comment Utility
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
Comment Utility
thanks greatly - seems to work a treat :-)
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

762 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now