Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 574171
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:48:09+00:00 2026-05-13T13:48:09+00:00

I have the following code that displays all folders and files within each folder.

  • 0

I have the following code that displays all folders and files within each folder.

The script is within the /intranets/fs/course_outlines/ folder -> default.asp

All the folders that this script is looking at are within the /intranets/fs/course_outlines/documents folder

Within the script below, it prints the “documents” folder and I am trying to remove that from displaying when it runs thru the for loop.

I am familiar with php, so I would know how to stop that from displaying the

documents

folder from printing with a conditional but I am unfamiliar with ASP

Also, the script prints out the html to be in this format:

<h2>Folder name</h2>
<ul>
<li><a href="path/to/file">File name</a></li>
<li><a href="path/to/file">File name</a></li>
etc..
</ul>

<h2>Folder name</h2>
<ul>
<li><a href="path/to/file">File name</a></li>
<li><a href="path/to/file">File name</a></li>
etc..
</ul>

etc..

I ran into some invalid html, which conflicts with a jQuery accordion effect I have applied to each folder & its contents. So any help on it ending with the appropriate closing tag after it prints the very last folder & its contents would be very helpful.

Thank you in advanced.

<h1>Course Outlines</h1>
<% ListFolderContents(Server.MapPath("/intranets/fs/course_outlines/documents")) %>
<% 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>" & vbCrLf)

     'Display a list of sub folders.

     for each item in folder.SubFolders
    ListFolderContents(item.Path)
     next

    'Display a list of files.
  Response.Write("<ul>" & vbCrLf)
    for each item in folder.Files
       url = MapURL(item.path)
    Response.Write("<li><a href=""" & url & """>" & item.Name & "</a></li>" & vbCrLf)
    next
    Response.Write("</ul>" & vbCrLf)
    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 %>

Screenshot of how it looks: http://grab.by/23Fq

Sample of some of the html it outputs

<h1>Course Outlines</h1> 
    <h2>documents</h2> 
<h2>APPROVED-2009-Business</h2> 
<ul> 
<li><a href="/intranets/fs/course_outlines/documents/APPROVED-2009-Business/BU 111 - Nagle.doc">BU 111 - Nagle.doc</a></li> 
<li><a href="/intranets/fs/course_outlines/documents/APPROVED-2009-Business/BU 112 - Ciccarelli.doc">BU 112 - Ciccarelli.doc</a></li> 
<li><a href="/intranets/fs/course_outlines/documents/APPROVED-2009-Business/BU 114 - Testa H-Cronauer.doc">BU 114 - Testa H-Cronauer.doc</a></li> 
<li><a href="/intranets/fs/course_outlines/documents/APPROVED-2009-Business/BU 115 - Testa H-Cronauer.doc">BU 115 - Testa H-Cronauer.doc</a></li> 
<li><a href="/intranets/fs/course_outlines/documents/APPROVED-2009-Business/TT 251-252-253-254 - Sutton.doc">TT 251-252-253-254 - Sutton.doc</a></li> 
</ul> 
<h2>APPROVED-2009-Humanities</h2> 
<ul> 
<li><a href="/intranets/fs/course_outlines/documents/APPROVED-2009-Humanities/ED 100 - List.doc">ED 100 - List.doc</a></li> 
<li><a href="/intranets/fs/course_outlines/documents/APPROVED-2009-Humanities/ED 110 - List.doc">ED 110 - List.doc</a></li> 
<li><a href="/intranets/fs/course_outlines/documents/APPROVED-2009-Humanities/ED 150 - Kelley.doc">ED 150 - Kelley.doc</a></li> 
</ul> 
<h2>APPROVED-2009-MAHPES</h2> 
<ul> 
<li><a href="/intranets/fs/course_outlines/documents/APPROVED-2009-MAHPES/HE 121 - Aragon-Dommer A.doc">HE 121 - Aragon-Dommer A.doc</a></li> 
<li><a href="/intranets/fs/course_outlines/documents/APPROVED-2009-MAHPES/HE 128 - Howell.doc">HE 128 - Howell.doc</a></li> 
<li><a href="/intranets/fs/course_outlines/documents/APPROVED-2009-MAHPES/HE 130 - Aragon.doc">HE 130 - Aragon.doc</a></li> 
<li><a href="/intranets/fs/course_outlines/documents/APPROVED-2009-MAHPES/SC 261 - Mezik.doc">SC 261 - Mezik.doc</a></li> 
</ul>

It displays an empty <ul></ul>

It has nothing within the the ul’s, so it seems to run once more before it knows to quick, can you help w/ the code to prevent that.

<h2>Last Folder to display</h2>
<ul>
<li><a href="/intranets/fs/course_outlines/documents/APPROVED-2009-Social Science/SS 240 - Verri.doc">SS 240 - Verri.doc</a></li>
<li><a href="/intranets/fs/course_outlines/documents/APPROVED-2009-Social Science/SS 241 - Verri.doc">SS 241 - Verri.doc</a></li>
<li><a href="/intranets/fs/course_outlines/documents/APPROVED-2009-Social Science/SS 245 - Elwood.doc">SS 245 - Elwood.doc</a></li>
<li><a href="/intranets/fs/course_outlines/documents/APPROVED-2009-Social Science/SS 246 - Hack Polkosnik.doc">SS 246 - Hack Polkosnik.doc</a></li>
</ul>
<ul>
</ul>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T13:48:09+00:00Added an answer on May 13, 2026 at 1:48 pm

    Try something like this. It only displays the folder if the sub-folder or sub-file count is greater than zero:

    Updated:

    <h1>Course Outlines</h1>
    <% ListFolderContents Server.MapPath("/intranets/fs/course_outlines/documents"), 0 %>
    <% 
    sub ListFolderContents(path, level)
        dim fs, folder, file, item, url, subFiles, subFolders
        set fs = CreateObject("Scripting.FileSystemObject")
        set folder = fs.GetFolder(path)
    
        if folder.SubFolders.Count > 0 or folder.Files.Count > 0 then
            'Display the target folder and info.
            if level > 0 then
                Response.Write("<h2>"& folder.Name &"</h2>" & vbCrLf)
            end if
    
            'Display a list of sub folders.
            for each item in folder.SubFolders
                ListFolderContents item.Path, level + 1
            next
    
            'Display a list of files.
            Response.Write("<ul>" & vbCrLf)
            for each item in folder.Files
                url = MapURL(item.path)
                Response.Write("<li><a href=""" & url & """>" & item.Name & "</a></li>" & vbCrLf)
            next
            Response.Write("</ul>" & vbCrLf)
        end if             
    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 
    %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a php script that steps through a folder containing tab delimited files,
I have the following code, but it displays all attribute options. I want to
I have the following code that fails to display object images. But displays normal
I have written a small plugin that displays tweets. following is the code that
I have following code that I am compiling in a .NET 4.0 project namespace
I have following code that does not work due to a being a value
I have following code that does not work: I never get to goToFoodDetail .
I have following code snippet that i use to compile class at the run
I have the following code that has @item.ID from razor: <a href=# id=deleteitem(@item.ID)>Delete</a> When
I have the following code that gets the MAC address of an interface: static

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.