• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 232
  • Last Modified:

retrieve extension of a variable that come from a file

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
1 Solution
Scott Fell, EE MVEDeveloperCommented:
stringSize = len(filenamecomplete)
x =InStrRev(filenamecomplete,".")
extensionSize = stringSize - x
resultingextension = right(filenamecomplete,extensionSize)

Open in new window

Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
You can do it with one line of code:

FileNameComplete = Right( fileName, InStrRev( fileName, ".") - 1)
coerraceAuthor Commented:
Works perfect.
Thank you

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now