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 6657359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:45:30+00:00 2026-05-26T01:45:30+00:00

I got some asp code to list the content of a folder (txt files

  • 0

I got some asp code to list the content of a folder (txt files only). I would like to know if there would be a way to list only the last 10 files created.

My application will create one file a day, using AAMMDD.txt as name.

I would like to be able to list only the 10 last files.

Does anyone here have some example that could share???

thank you in advance.

here is the code I found that list everything (I already made some changes on the script):

<%
Const ImageFilePath = "logs"

Dim objFSO
Dim objFolder
Dim objFile

Dim strFileName
Dim strFileExtension

Dim blnShowFiles

If Request.QueryString("ShowFiles") = "" Then
    blnShowFiles = True
Else
    blnShowFiles = CBool(Request.QueryString("ShowFiles"))
End If


    Set objFSO = Nothing
%>

<style>

ul.dropdownPC, ul.dropdownPC li, ul.dropdownPC ul 
            {
    list-style: none;
    margin: 8px;
    float: left;
    vertical-align: middle;
    padding:0px;
    border:solid;
    border-width:0px;
    border-color:#ccc;
    background-color: #fff;
}
ul.dropdownPC li 
            {
    padding:5px;
    border-width:0px;
}
</style>

<ul class="dropdownPC dropdown-horizontal">
<%
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(Server.MapPath(ImageFilePath))

For Each objFile In objFolder.Files
    strFileExtension = LCase(Mid(objFile.Name, InStrRev(objFile.Name, ".", -1, 1) + 1))

    If strFileExtension = "txt" Then
        %>
        <li><a href="<%= ImageFilePath & "/" & objFile.Name %>" target=_blank><img width="80" height="80" border="0" src="images/texticon01.png"><br><center><%= objFile.Name %></center></a>
        <%
        If blnShowFiles Then
            %>
            <!-- <%= objFile.Name %> --></li>
            <%
        Else
            %>
            <!-- <a href="<%=ImageFilePath & "/" & objFile.Name %>">View `Logs</a> --></li>`
            <%
        End If
        %>

        <%
    End If
Next ' objFile

Set objFolder = Nothing
Set objFSO = Nothing
%>
  • 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-26T01:45:31+00:00Added an answer on May 26, 2026 at 1:45 am

    Put the file names and creation dates into a recordset, sort it and get top ten records.

    <%
    Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
    Set objFolder = objFSO.GetFolder(Server.MapPath(ImageFilePath))
    
    'Required ADO Constants
    Const adVarChar = 200
    Const adDate = 7
    Dim objRs
    Set objRS = Server.CreateObject("Adodb.Recordset") 'Recordset for the sort
    objRs.Fields.Append "FileName", adVarChar, 255
    objRs.Fields.Append "CreateDate", adDate
    objRs.Open
    
    For Each objFile In objFolder.Files
        strFileExtension = LCase(Mid(objFile.Name, InStrRev(objFile.Name, ".", -1, 1) + 1))
        If strFileExtension = "txt" Then 'All Text Files Into Recordset
            objRS.AddNew Array("FileName", "CreateDate"), Array(objFile.Name, objFile.DateCreated)
            objRs.Update
        End If
    Next ' objFile
    
    objRs.Sort = "CreateDate Desc"
    For i = 1 To 10
    If objRS.Eof Then Exit For 
    %>
            <li><a href="<%= ImageFilePath & "/" & objRS("FileName") %>" target=_blank><img width="80" height="80" border="0" src="images/texticon01.png"><br><center><%= objRS("FileName") %></center></a>
            <% If blnShowFiles Then %>
            <!-- <%= objRS("FileName") %> --></li>
            <% Else %>
            <!-- <a href="<%=ImageFilePath & "/" & objRS("FileName") %>">View `Logs</a> --></li>`
            <% End If %>
    <%
    objRS.MoveNext
    Next
    Set objFolder = Nothing
    Set objFSO = Nothing
    objRS.Close
    Set objRS = Nothing
    %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got an asp:TextArea that I would like to do some processing (filtering a
I've got an asp.net page that has c# code-behind that does some stuff in
I've got an ASP.NET application, which calls this code at some point, to display
I've got some trouble with jQuery script on my Asp.net page. During first load
I've got some RESTful services running in a pure WCF context (i.e. ASP.NET compatibility
I've got to do some significant development in a large, old, spaghetti-ridden ASP system.
We've got a classic ASP application that is putting out some very large reports,
Okay still fighting with doing some SqlCacheDependecy in my Asp.net MVC application I got
I've got an ASP.NET app that requires Windows Integrated Security. For some reason, I
Got some code that is not mine and its producing this warning atm: iehtmlwin.cpp(264)

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.