retrieve extension of a variable that come from a file

Posted on 2014-09-01
Last Modified: 2014-09-02
Hello we have in vbscript some coding to grab file names from directories and put in a dynamic variable that change frequent. Now from that variable we want to put in another variable the extension only of what it was the file that now is a variable. For example we have a variable called "filenamecomplete", this is the variable where the vbscript store the name of the filename grabbed, and we want in the variable "resultingextension" store the extension of that variable that originally was a file name. Look these examples with some value examples of "filenamecomplete" and what we want to store in "resultingextension":

filenamecomplete (string var. value   resultingextension (variable to store extension)

filename.doc                                                 .doc
filename.fil.doc.                                            .doc
filename.fil.docx                                           .docx
filenamefile.file.file.aa.dd.ff.dddms          .ddms
filename.ff.dd.ww.exteneioep                   .exteneioep

   Like you see sometimes could be extensions longer than 3 and 4 characters and could be "." characters in different positions of the string "filenamecomplete".

   Someone could help with an example vbscript code to reach this result?
   The vbscript code is of course to use in a normal ".asp" file, we don't use ASP.NET, just simply ASP and to put the code in the middle of a normal call of vbscript in ASP files, in other words put the code in the middle of:


put code here


Thank you so much
Question by:coerrace
    LVL 52

    Accepted Solution

    stringSize = len(filenamecomplete)
    x =InStrRev(filenamecomplete,".")
    extensionSize = stringSize - x
    resultingextension = right(filenamecomplete,extensionSize)

    Open in new window

    LVL 32

    Expert Comment

    by:Big Monty
    You can do it with one line of code:

    FileNameComplete = Right( fileName, InStrRev( fileName, ".") - 1)

    Author Closing Comment

    Works perfect.
    Thank you

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Suggested Solutions

    This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
    Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
    This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
    Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…

    759 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

    14 Experts available now in Live!

    Get 1:1 Help Now