ASP Page shows all files need to exclude files Help

Windows 2003 IIS 6 Web server

The below code works http://localhost/music_9.asp

Displays a full list of the contents of the mp3 music albums folder.

1. Would like the list to only show .mp3 and .m4a files
2. When the list is presented can a button be placed next to the file that one could click and then it will play that mp3 or m4a file


<% 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.

     rootPath = Server.MapPath("/")
     url = Right(path, Len(path) - Len(rootPath))
     MapURL = Replace(url, "\", "/")

end function %>


Looking to display all mp3/m4a files and then one can play any song by clicking on it

Any ideas Thanks
Tom
LVL 23
Thomas GrassiSystems AdministratorAsked:
Who is Participating?
 
Dave BaldwinConnect With a Mentor Fixer of ProblemsCommented:
I would remove the spaces in the folder names first and make sure that the case is the same everywhere you use it.  Like this:

/mp3/MP3MusicAlbums
0
 
Dave BaldwinFixer of ProblemsCommented:
I dont' think you need a button.  I think they will play in whatever application the user has assigned to that extension.
0
 
Thomas GrassiSystems AdministratorAuthor Commented:
Dave

when I click on the file it comes back with http 404 page can not be found

http://www.tgcsnet.com/music_9.asp

check it out

IUSR has Read & Execute, List Contents, and Read permissions on that folder.

Also want to only list .mps and .m4a can that be done with the code I have?
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
Dave BaldwinFixer of ProblemsCommented:
There is something wrong with the way you are creating the URLs.  When I go directly to this song URL, it plays fine.
http://www.tgcsnet.com/mp3/MP3%20Music%20Albums/Deep%20Purple/Machine%20Head/01%20-%20Highway%20Star%20%28LP%20Version%29.mp3

The first thing I suggest is getting rid of the spaces in the directory names.  Or at least converting them to underscores '_'.  You may find that the parsing of the folder names is failing because of the spaces.  I also don't see the main directory http://www.tgcsnet.com/mp3 in your URLs either.
0
 
Thomas GrassiSystems AdministratorAuthor Commented:
Yes that works that way so what is wrong with the way the url is being created?

code:

<% 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.

     rootPath = Server.MapPath("/")
     url = Right(path, Len(path) - Len(rootPath))
     MapURL = Replace(url, "\", "/")

end function %>


This is what is being created

http://www.tgcsnet.com/Albums/Deep%20Purple/Machine%20Head/01%20-%20Highway%20Star%20(LP%20Version).mp3


vs what works

http://www.tgcsnet.com/mp3/MP3%20Music%20Albums/Deep%20Purple/Machine%20Head/01%20-%20Highway%20Star%20%28LP%20Version%29.mp3 


I see a big difference but not sure what to change?

I am new to this type of coding...
0
 
Thomas GrassiSystems AdministratorAuthor Commented:
Dave

Yes I was thinking that two

I will make that change tonight and test

Any thoughts about how I can only display .MP3 and .M4A and WMA files
0
 
Dave BaldwinFixer of ProblemsCommented:
Not until it actually works.
0
 
Thomas GrassiSystems AdministratorAuthor Commented:
Dave,

Made the change still does not work I think it is the code? Need your help on that please.

Now it looks like this

http://www.tgcsnet.com/lbums/Deep%20Purple/Machine%20Head/01%20-%20Highway%20Star%20(LP%20Version).mp3



Code:

code:

<% ListFolderContents(Server.MapPath("/mp3/mp3musicalbums")) %>
<% 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.

     rootPath = Server.MapPath("/")
     url = Right(path, Len(path) - Len(rootPath))
     MapURL = Replace(url, "\", "/")

end function %>

I restarted IIS just to make sure the changes to the alias was made

Still does not work

Any ideas

 Thanks
0
 
Dave BaldwinFixer of ProblemsCommented:
0
 
Thomas GrassiSystems AdministratorAuthor Commented:
Dave

any time to look at the code today?

It is something in my code that is causing this?

My ASP code knowledge is ok but by no means expert level.

Any help would be great.
0
 
Thomas GrassiSystems AdministratorAuthor Commented:
Dave

Got it working

Going to post another question about how to only show .mp3 .m4a and .wma files.

Thanks for your help
0
 
Dave BaldwinFixer of ProblemsCommented:
You're welcome, glad to help.
0
All Courses

From novice to tech pro — start learning today.