-1

I have a folder with 114,000 files in it (not under my control) and I want to list only the latest 100 of them that have been modified. So I hobbled together an ASP script from different sources, but it's giving me an internal server error when I run it.

<%
Function SortFiles(files)
    ReDim sorted(files.Count - 1)
    Dim file, i, j
    i = 0
    For Each file in files
        Set sorted(i) = file
        i = i + 1
    Next
    For i = 0 to files.Count - 2
    For j = i + 1 to files.Count - 1
        If sorted(i).DateLastModified < sorted(j).DateLastModified Then
            Dim tmp
            Set tmp = sorted(i)
            Set sorted(i) = sorted(j)
            Set sorted(j) = tmp
        End If
    Next
    Next
    SortFiles = sorted
End Function

dim fileserver,files,file,i
set fileserver=Server.CreateObject("Scripting.FileSystemObject")
set files=fileserver.GetFolder(Server.MapPath(".")).Files

i = 0
For Each file in SortFiles(files)
    Response.write(x.Name & "\t" & x.Size & "\n")
    i = i + 1
    If i > 100 Then
        Exit For
    End If
Next

set fo=nothing
set files=nothing
%>

The files I want listed just need to have their name and size separated by new lines. I am new to ASP so I'm not sure how to debug this.

Jack Cole
  • 1,528
  • 2
  • 19
  • 41

1 Answers1

0

Move the code from aspx to aspx.cs (code behind) and you can debug it by adding breakpoint, and F10/F11 to step over/step into. I don't know if you can debug inline code, looks like you can by some SO answer.

At first glance, SortFiles does not return a list of file, so it can not be used in a For Each loop.

For Each file in SortFiles(files) //exception

And what is this for?

SortFiles = sorted

I don't know VB, but you can debug yourself.

Community
  • 1
  • 1
kennyzx
  • 12,845
  • 6
  • 39
  • 83