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
%>
Put the file names and creation dates into a recordset, sort it and get top ten records.