Solved

Extract filename from full path

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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

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…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

622 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