Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Nov 2002
    Location
    India
    Posts
    159
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Files in a folder

    Hi all,

    I got this piece of code from a link on this forum itself. It is to list in a tree structure all the files and subfolders underneath a certain folder. The code being used is as follows

    ==============================================
    <%@ LANGUAGE="VBScript" %>
    <%
    Response.CacheControl = "Private"
    %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/strict.dtd">
    <% '***************************************************************************
    '* ASP Directory Listing *
    '* *
    '* Do not remove this notice. *
    '* *
    '* Copyright 1999, 2000 by Mike Hall. *
    '* Please see http://www.brainjar.com for documentation and terms of use. *
    '***************************************************************************
    %>
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
    <title>ASP Directory Listing Demo</title>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
    <link rel="stylesheet" type="text/css" href="style/stds.css" />
    </head>
    <body>


    <ul>
    <%
    Dim ctryCode
    ctryCode = trim(Request.QueryString ("ctryCode"))

    if ctryCode = "eos" then
    Response.Write ("<div align=center><h1>EOS</h1></div>")
    ListFolderContents(Server.MapPath("/EOST"))
    end if

    %>
    </ul>

    </body>
    </html>

    <% sub ListFolderContents(path)

    dim fs, folder, file, item, url

    set fs = CreateObject("Scripting.FileSystemObject")
    set folder = fs.GetFolder(path)

    Response.Write("<font class=dnb-topic-light-bg><li><b>" & folder.Name & "</b></font>")

    Response.Write("<ul>" & vbCrLf)

    'Display a list of sub folders.

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

    'Display a list of files.

    for each item in folder.Files
    url = MapURL(item.path)
    Response.Write("<li><font class=dnb-link-light-bg><a href=""" & url & """ target=_doc>" & item.Name & "</a></font></li>" & vbCrLf)
    next

    Response.Write("</ul>" & vbCrLf)

    Response.Write("</li>" & vbCrLf)

    end sub

    function MapURL(path)

    dim rootPath, url

    'Convert a physical file path to a URL for hypertext links.

    rootPath = Server.MapPath("/")
    on error resume next
    url=path
    MapURL = Replace(url, "\", "/")

    end function %>
    ============================================
    now what i find is that the subfolders/files are being listed in ascednding order of creation/modified date rather than alphabetically.

    how do i get the listing of all files/subfolders in alphabetical order?

    Thanks in advance, mates!

  • #2
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    The best idea would be to re-write the above code to put all the files into an array then write a sub to alphabatize the array. Then once thats done, you output the array onto the page.
    OracleGuy


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •