Solved

trim extension when using fso

Posted on 2004-09-29
12
416 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

760 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

19 Experts available now in Live!

Get 1:1 Help Now