PDA

View Full Version : Read .txt files by Date First...


isaaclloyd
06-15-2005, 01:41 AM
My hosting service isn't very helpful when it comes to databases so I am trying to get away with using text files. I am working on a script where it reads and displays each textfile in the folder. And so far it works great, however there is one problem that I am hoping someone can help me with. I need it to read and display the "last modified" or "last created" text file FIRST. Here is what I have so far for the script. Any comments or suggestions would greatly be appreciated. Thanks for your time.


~Isaac~


The Script



<%
'======= Parameters =========

myAbsolutePath = Server.MapPath("/test/txt/") ' The absolute path to the dir to list
URLdir = "/test/txt/" 'The Path to My files starting from your web root dir
FileNameExtension = ".txt" 'The file name extension of the files to be listed
'====== End Parameters =======



Function DirFiles (FolderPath, FileNameExtention)
Set FSO = CreateObject("Scripting.FileSystemObject")
Set Folder = FSO.GetFolder(FolderPath)
Set Files = Folder.Files

If Files.Count > 0 Then
For Each nFile In Files
If Right(nFile.Name,4)=FileNameExtention then

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile(Server.MapPath(URLdir & nFile.Name))
Do While Not objTextFile.AtEndOfStream
Response.Write objTextFile.ReadLine & "<BR>" & vbCrLf
Loop

Response.Write "<HR COLOR='#d20000'>"
objTextFile.Close

end if
Next
else
Response.Write "No Messages Found."
End If


Set FSO = nothing
Set Folder = nothing
Set Files = nothing
Set objTextFile = Nothing
Set objFSO = Nothing
End function

DirFiles myAbsolutePath, FileNameExtension

%>

Morgoth
06-15-2005, 04:07 AM
Here is a link that will show you how to grab the creation date of the files, among others.
http://www.w3schools.com/asp/asp_ref_file.asp

So my suggestion is to grab each file's creation date and name and store that information in an array. Then sort that array depending on the date.

It sounds really simple, and it's probibly the best method.

isaaclloyd
06-15-2005, 04:27 AM
Any suggestions on how I would go about sorting/reading/displaying the .txt files with that date array? Thanks for your time.


~Isaac Lloyd~

Morgoth
06-15-2005, 04:38 AM
Since you store the name and date into the array, you use the date to sort the array.

Bubble sorting will work.
I didn't a quick google search and this looks like it might help you.
http://www.webmasterworld.com/forum13/275.htm

After you have that all sorted out, you use the name of the text file in the array and use a for loop to grab each file's contents the same way you are doing it now. (With minor changes, of course.)