Solved

trim extension when using fso

Posted on 2004-09-29
12
429 Views
Last Modified: 2010-05-18
I am using FSO to build a dynamic list/menu with the file name from my folder.

What I would like to do is display the file name without the extension in the list/menu.

A bit of what I am using:

<%For Each objFile In objFolder.Files
          arr = split(objFile.Name, ".") 'split the name and the extension into an array
          If (arr(UBound(arr)) = "wma") then
                  response.Write("<option value=""mms://myStreamURL.ath.cx" & objFile.Name & """>" & objFile.Name & "</option>")                
          End If
     Next

Think this is an easy one, just lots of point cuz I'm lazy and in a hurry ;)

Thanks!
0
Comment
Question by:nickleplated
[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
  • 5
  • 3
  • 3
  • +1
12 Comments
 
LVL 19

Expert Comment

by:Shauli
ID: 12180268
Left(objFile.Name, Len(objFile.Name)-4)

S
0
 
LVL 19

Expert Comment

by:Shauli
ID: 12180298
Which means that you dont need to split. However, if you do want to split, then arr(0) would contain the name and arr(1) would contain the extension.

S
0
 
LVL 15

Expert Comment

by:Colosseo
ID: 12180314
You use UBound to get the extension so LBound should give you the name

cheers


Scott
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 19

Assisted Solution

by:Shauli
Shauli earned 400 total points
ID: 12180339
Or with your text (Split option)

          arr = split(objFile.Name, ".") 'split the name and the extension into an array
          If (arr(1) = "wma") then
                  response.Write("<option value=""mms://myStreamURL.ath.cx" & arr(0) & """>" & arr(0) & "</option>")                
          End If

Left option:

          If Right( objFile.Name, 3) = "wma" then
                  response.Write("<option value=""mms://myStreamURL.ath.cx" &  Left(objFile.Name, Len(objFile.Name)-4) & """>" &  Left(objFile.Name, Len(objFile.Name)-4) & "</option>")                
          End If

S
0
 
LVL 1

Author Comment

by:nickleplated
ID: 12180344
ok - so I have:

<%For Each objFile In objFolder.Files
 
          arr = split(objFile.Name, ".") 'split the name and the extension into an array
          If (arr(UBound(arr)) = "wma") then
             
                  response.Write("<option value=""mms://myStreamURL.ath.cx/" & objFile.Name & """>" & Left(objFile.Name, Len(objFile.Name)-4) & "</option>")                
          End If
     Next
       %>

Which seems to work perfectly.
I was doing the split to make sure that it only gave me "wma" files // for obvious reasons.

Is there a tighter way to achieve this?

Thanks for the fast responses!
0
 
LVL 8

Expert Comment

by:mladenovicz
ID: 12180369
oFSO.GetBaseName(objFile.Name)

where oFSO is
dim oFSO as FileSystemObject
0
 
LVL 1

Author Comment

by:nickleplated
ID: 12180373
let me add something?

Some files may contain additional "."

ie:
AFRICANISM.MIXED.BY.BOB.SINCLAR.wma
0
 
LVL 8

Expert Comment

by:mladenovicz
ID: 12180384
If oFSO.GetExtensionName(objFile.Name) ="wma" Then
0
 
LVL 19

Expert Comment

by:Shauli
ID: 12180390
If you split, then use the lbound, which contain the name without the extenstion:

response.Write("<option value=""mms://myStreamURL.ath.cx/" & objFile.Name & """>" & arr(0) & "</option>")  

S
   
0
 
LVL 19

Expert Comment

by:Shauli
ID: 12180412
See above, nickleplated , the LBOUND contains the name, the UBOUND contain the extenstion. Which means that arr(0) is the name without the extenstion, nomatter how many dots you have.

S
0
 
LVL 8

Accepted Solution

by:
mladenovicz earned 100 total points
ID: 12180416
GetBaseName will work with additional dots and if extension length is less than 3 chars
0
 
LVL 1

Author Comment

by:nickleplated
ID: 12180559
Thanks to all, below (IMHO) seems the tightest

<%For Each objFile In objFolder.Files  
           arr = split(objFile.Name, ".") 'split the name and the extension into an array
          If (arr(1) = "wma") then
                  response.Write("<option value=""mms://myStreamURL/" & objFile.Name & """>" & arr(0) & "</option>")
          End If
     Next
%>

Cheers to all.
0

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

730 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