Solved

Capture file extention

Posted on 2007-12-07
6
199 Views
Last Modified: 2012-06-27
I need to capture the file extension. I have collected the full filename and extension. I used to use;

------------------------------
strAtPos = Instr(checkFile,".")
strExtension = Mid(checkFile,strAtPos+1)
------------------------------

But this does not take account of people who use dots in their file names, Such as test.this.file.txt

I also want to avoid just grabbing the last 3 characters as some file types have 4... such as html or jpeg.

So in the example 'test.this.file.txt' what would be the best way to get the file extension allowing for various file types with various lenghts.


Kind regards

Abiel M de Groot
0
Comment
Question by:Abiel de Groot
[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
6 Comments
 
LVL 19

Expert Comment

by:Delphineous Silverwing
ID: 20426801
The extension is the last dot "." in the file name.  You can set the routine to loop until the last dot is found, or search from the right.
0
 
LVL 18

Expert Comment

by:Morcalavin
ID: 20426833
You can try a RegExp to grab the last extension:

dim regex, ext, filename

filename = "test.1.2.txt"

set regex = new RegExp
regex.pattern = "\.(.*)+$"

ext = regex.match(filename)

ext should be an array containing the matches if I remember.  Been a while since I've done regexes in ASP.
0
 
LVL 5

Author Comment

by:Abiel de Groot
ID: 20427000
I have this but the server hangs... and I have to reboot!
checkFile Is the full file name with extension

Any Ideas?
strAtPos = Instr(checkFile,".")
 
Do Until strAtPos = 0
strAtPos = Instr(strAtPos,checkFile,".")	
Loop

Open in new window

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 39

Accepted Solution

by:
Pratima Pharande earned 250 total points
ID: 20427040
Dim WordArray

then do the split, using a space as the split indicator

WordArray = Split(NameStr, ". ")

WordArray(1)   , you will get extention
0
 
LVL 18

Assisted Solution

by:Morcalavin
Morcalavin earned 250 total points
ID: 20427287
@pratima_mcs

That would only grab the second place, ie if the string is file.1.txt you would end up with 1.

However, you could do something like:
Dim WordArray

WordArray = Split(NameStr, ".")
Response.Write WordArray(Ubound(WordArray) - 1)
0
 
LVL 5

Author Comment

by:Abiel de Groot
ID: 20427489
Almost right...
WordArray(Ubound(WordArray) - 1) returns the file name...

WordArray(Ubound(WordArray)) returns the extension


Kind regards to all

Abbey
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
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…

630 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