ASP利用FSO组件如何按时间升序排列实现逐个显示某文件夹下的文件名(不用数据库)

来源:百度知道 编辑:UC知道 时间:2024/05/16 11:55:16
例如:某文件夹下有文件
123.txt 创建日期为 2007-2-1
345.txt 创建日期为 2007-4-5
567.txt 创建日期为 2006-12-12
如何才能实现打开页面后先显示创建日期最早的即567.txt,处理完567.txt自动删除该文件,自动显示2007-2-1,最好日期时间精确到秒,到日期也无所谓,要求在本页程序完成,一定不要使用数据库.越详细越好.谢谢!
不好意思我问题没提明白,创建日期是用FSO取出来的,并不是数据库读出来的。

给你一个思路把日期变成"数"的格式如:2007-2-1变成20070201,之后比这些数的大小再排序就可以了.

使用冒泡法吧
代码如下:

<%
dim folderPath
folderPath = "G:\中国五金商机网\web" '修改成你要的路径,对这个路径下的文件按日期排列
dim fso,f
set fso=server.CreateObject("Scripting.filesystemobject")
set fld=fso.Getfolder(folderPath)
for each f in fld.files
dd = f.DateLastModified
dd1 = year(dd) & "-" & right("0" & month(dd),2) & "-" & right("0" & day(dd),2) & " " & hour(dd) & ":" & Minute(dd) & ":" & right("0" & Second(dd),2) & "   "
str = str & dd1 & f.name & "|"
next
tmp = split(str,"|")
for j = 0 to ubound(tmp)
str1 = ""
for i = 0 to ubound(tmp)
if i = ubound(tmp) then exit for
if tmp(i) <= tmp(i+1) then