title: Listing a folder structure in Classic ASP
body: <p>I've developed a secure page in ASP for the company I work for. There is a landing (login page) that once you are authenticated you are taken to a page that has links to several sub pages. Each sub page has a folder structure. For example: There is a heading for Meeting Minutes and then underneath and indented are links referencing PDFs that contain the information. There may be 3 or 4 headings with documents linked beneath.</p>
  
  <p>The original version had a PHP script that ran and would sync up the live site on the server from a folder structure that would be mimicked onto the live site.  So if I had a folder called Folder1 and sub folders named test1 test2 test3.. the live site would display them accordingly.  Since the site is now in ASP and not PHP.. the PHP script no longer works (since PHP doesn't play well with ASP).</p>
  
  <p>I found a snippet online that somewhat works for what i'm trying to achieve (i.e. Folder/Subfolder/File Name structure), however i'm stuck at the moment with how to link the files so they open when clicked. I keep seeing a %25 in the file name. I know %20 is the same as a blank space and since I am dealing with file and folder names that contain spaces, this appears to be my issue.  I've tried adding in a %20 but the spaces become "%2520".  </p>
  
  <p>If you look at the code below, there is a link towards the bottom that calls "MapURL". I have that link commented out at the moment as I was trying to figure out where the %25 was coming from. 
  Anyone have any thoughts on how to get the links to work? </p>
  
  <p>Here is the snippet.</p>
  
  
  
  <pre class="lang-vb prettyprint-override"><code>dim path 
  path = "PATH TO THE FOLDER ON THE SERVER"
  
  ListFolderContents(path)
  
  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("&lt;ul&gt;&lt;b&gt;" &amp; folder.Name &amp; "&lt;/b&gt;") '- " _
   '  &amp; folder.Files.Count &amp; " files, ")
   'if folder.SubFolders.Count &gt; 0 then
   '  Response.Write(folder.SubFolders.Count &amp; " directories, ")
   'end if
   'Response.Write(Round(folder.Size / 1024) &amp; " KB total." _
   '  &amp; "&lt;/ul&gt;" &amp; vbCrLf)
  
   Response.Write("&lt;ul&gt;" &amp; vbCrLf)
  
   'Display a list of sub folders.
  
   for each item in folder.SubFolders
     ListFolderContents(item)
   next
  
   'Display a list of files.
  
   for each item in folder.Files
     'url = MapURL(item.path)
     'Response.Write("&lt;li&gt;&lt;a href=" &amp; url &amp; "&gt;" &amp; item.Name &amp; "&lt;/a&gt; - " _
  
     Response.Write("&lt;li&gt;&lt;a href=" &amp; Replace(item.path," ","%") &amp; "&gt;" &amp; item.Name &amp; "&lt;/a&gt; - " _
       &amp; item.Name &amp; "&lt;/a&gt;" _
       &amp; "&lt;/li&gt;" &amp; vbCrLf)
   next
  
   Response.Write("&lt;/ul&gt;" &amp; vbCrLf)
   Response.Write("&lt;/ul&gt;" &amp; 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
  </code></pre>