Solved

trim extension when using fso

Posted on 2004-09-29
12
418 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
  • 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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 While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

867 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

15 Experts available now in Live!

Get 1:1 Help Now