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

x
?
Solved

Capture file extention

Posted on 2007-12-07
6
Medium Priority
?
202 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
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 39

Accepted Solution

by:
Pratima Pharande earned 1000 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 1000 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

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…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

824 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