?
Solved

trim extension when using fso

Posted on 2004-09-29
12
Medium Priority
?
434 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 1600 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 400 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month14 days, 11 hours left to enroll

770 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