Solved

ASP Code help needed

Posted on 2013-12-11
8
405 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 53

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
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 53

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 500 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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

A phishing scam that claims a recipient’s credit card details have been “suspended” is the latest trend in spoof emails.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
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…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

717 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