[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

ASP Code help needed

Posted on 2013-12-11
8
Medium Priority
?
414 Views
Last Modified: 2013-12-11
My code is below and works great

Runs on a windows 2003 server using IIS 6 ASP

I would just like to show the following file type only

.MP3 .M4A and .WMA

Is there a way to do that currently is lists all files in the folders.

<% ListFolderContents(Server.MapPath("/mp3/mp3 music albums")) %>
<% sub ListFolderContents(path)
     dim fs, folder, file, item, url
     set fs = CreateObject("Scripting.FileSystemObject")
     set folder = fs.GetFolder(path)
    'Display the target folder and info.
     Response.Write("<h2>"& folder.Name &"</h2>")
     'Display a list of sub folders.
     for each item in folder.SubFolders
                ListFolderContents(item.Path)
     next
     'Display a list of files.
Response.Write("<ul>")
    for each item in folder.Files
       url = MapURL(item.path)
        Response.Write("<li><a href=""" & url & """>" & item.Name & "</a></li>")
    next
        Response.Write("</ul>")
   end sub
   function MapURL(path)
     dim rootPath, url
     'Convert a physical file path to a URL for hypertext links.
     url = "/mp3/" & Right(path, Len(path) - 9)
     MapURL = Replace(url, "\", "/")
end function  %>

Open in new window

0
Comment
Question by:Thomas Grassi
[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
  • 3
  • 3
  • 2
8 Comments
 
LVL 33

Expert Comment

by:Big Monty
ID: 39711535
you'll need to use the GetExtension method.  try something like this:

<% ListFolderContents(Server.MapPath("/mp3/mp3 music albums")) %>
<% sub ListFolderContents(path)
     dim fs, folder, file, item, url
     set fs = CreateObject("Scripting.FileSystemObject")
     set folder = fs.GetFolder(path)
    'Display the target folder and info.
     Response.Write("<h2>"& folder.Name &"</h2>")
     'Display a list of sub folders.
     for each item in folder.SubFolders
                ListFolderContents(item.Path)
     next
     'Display a list of files.
Response.Write("<ul>")
    for each item in folder.Files
       If UCase(fs.GetExtensionName(item.name)) = "MP3" Then
          url = MapURL(item.path)
          Response.Write("<li><a href=""" & url & """>" & item.Name & "</a></li>")
       end if
    next
        Response.Write("</ul>")
   end sub
   function MapURL(path)
     dim rootPath, url
     'Convert a physical file path to a URL for hypertext links.
     url = "/mp3/" & Right(path, Len(path) - 9)
     MapURL = Replace(url, "\", "/")
end function  %>

Open in new window

0
 
LVL 54

Expert Comment

by:Scott Fell, EE MVE
ID: 39711584
I can think of several ways to do this.  You could use item.GetExtensionName and check for something good.  Here is another function to add to your code.

function goodExt(t)
  ext= right(t,3)
  if instr(g,ext)>0 then
       goodExt="yes"
       else
       goodExt="no"
  end if
end function

Open in new window

Next modify this part of your code.
 for each item in folder.Files
       url = MapURL(item.path)
       if goodExt(item.Name)="yes" then
             Response.Write("<li><a href=""" & url & """>" & item.Name & "</a></li>")
      end if
    next

Open in new window

0
 
LVL 23

Author Comment

by:Thomas Grassi
ID: 39711587
Thanks for responding

Will give a try.

How about the other two extensions .m4a and .wma can they be added on the same command?

Is there a place where I can read up on this command?
0
Looking for a new Web Host?

Lunarpages' assortment of hosting products and solutions ensure a perfect fit for anyone looking to get their vision or products to market. Our award winning customer support and 30-day money back guarantee show the pride we take in being the industry's premier MSP.

 
LVL 54

Expert Comment

by:Scott Fell, EE MVE
ID: 39711599
I forgot something in my code.. very important



function goodExt(t)
  ext= right(t,3)
  g="MP3 M4A WMA"
  if instr(g,ext)>0 then
       goodExt="yes"
       else
       goodExt="no"
  end if
end function

Open in new window

0
 
LVL 33

Expert Comment

by:Big Monty
ID: 39711603
you can read up on it here:

http://msdn.microsoft.com/en-us/library/x0fxha2a%28v=VS.85%29.aspx

you can check for multiple extensions, just add an OR close to your if statement:

If UCase(fs.GetExtensionName(item.name)) = "MP3" Then or UCase(fs.GetExtensionName(item.name)) = "MP4" Then
0
 
LVL 23

Author Comment

by:Thomas Grassi
ID: 39711778
try the code with multiple extensions got this

Microsoft VBScript compilation  error '800a0400'

Expected statement

/music_19.asp, line 15
If UCase(fs.GetExtensionName(item.name)) = "MP3" Then or UCase(fs.GetExtensionName(item.name)) = "M4A" Then or UCase(fs.GetExtensionName(item.name)) = "WMA" Then
------------------------------------------------------^

The ^ is under the OR

This is ASP classic  music_19.asp does that matter?

The original one with just the .mp3 worked only .mp3 files appeared.

Now I need the other two .m4a
0
 
LVL 33

Accepted Solution

by:
Big Monty earned 2000 total points
ID: 39711779
change it to:

If UCase(fs.GetExtensionName(item.name)) = "MP3" or UCase(fs.GetExtensionName(item.name)) = "M4A" or UCase(fs.GetExtensionName(item.name)) = "WMA" Then
0
 
LVL 23

Author Closing Comment

by:Thomas Grassi
ID: 39711806
Works great thanks

now to testing on all browsers and smart devices.
0

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

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

When the s#!t hits the fan, you don’t have time to look up who’s on call, draft emails, call collaborators, or send text messages. An instant chat window is definitely the way to go, especially one like HipChat. HipChat is a true business app. An…
Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…

656 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