Solved

ASP Code help needed

Posted on 2013-12-11
8
401 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
  • 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 52

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
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 
LVL 52

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

803 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