<HTML> <HEAD> <TITLE>文件排序演示</TITLE> </HEAD> <BODY> <% " 设定一个演示目录,:) CONST DIRECTORY = "/" " 用常数定义排序方式 CONST FILE_NAME = 0 "按照名字排序……依次类推 CONST FILE_EXT = 1 CONST FILE_TYPE = 2 CONST FILE_SIZE = 3 CONST FILE_CREATED = 4 CONST FILE_MODIFIED = 5 CONST FILE_ACCESSED = 6 "获得 排序命令,默认为按照名字排序 req = Request("sortBy") If Len(req) < 1 Then sortBy = 0 Else sortBy = CInt(req) req = Request("priorSort") If Len(req) < 1 Then priorSort = -1 Else priorSort = CInt(req) "设置倒序 If sortBy = priorSort Then reverse = true priorSort = -1 Else reverse = false priorSort = sortBy End If " 接下来开始我们真正的代码了。。。 path = Server.MapPath(DIRECTORY) Set fso = CreateObject("Scripting.FileSystemObject") Set theCurrentFolder = fso.GetFolder(path) Set curFiles = theCurrentFolder.Files " 给这些文件做一个循环 Dim theFiles() ReDim theFiles(500) " 我随便定的一个大小 currentSlot = -1 " start before first slot " 我们将文件的所有相关信息放到数组里面 For Each fileItem in curFiles fname = fileItem.Name fext = InStrRev(fname, ".") If fext < 1 Then fext = "" Else fext = Mid(fname,fext+1) ftype = fileItem.Type fsize = fileItem.Size fcreate = fileItem.DateCreated fmod = fileItem.DateLastModified faccess = fileItem.DateLastAccessed currentSlot = currentSlot + 1 If currentSlot > UBound(theFiles) Then ReDim Preserve theFiles(currentSlot + 99) End If " 放到数组里 theFiles(currentSlot) = Array(fname,fext,ftype,fsize,fcreate,fmod,faccess) Next " 现在都在数组里了,开始下一步 fileCount = currentSlot " 文件数量 ReDim Preserve theFiles(currentSlot) " 排序 " (8 表示 string) If VarType(theFiles(0)(sortBy)) = 8 Then If reverse Then kind = 1 Else kind = 2 " 给字符排序 Else If reverse Then kind = 3 Else kind = 4 "数字、时间。。。 End If For i = fileCount TO 0 Step -1 minmax = theFiles(0)(sortBy) minmaxSlot = 0 For j = 1 To i Select Case kind Case 1 mark = (strComp(theFiles(j)(sortBy), minmax, vbTextCompare) < 0) Case 2 mark = (strComp(theFiles(j)(sortBy), minmax, vbTextCompare) > 0) Case 3 mark = (theFiles(j)(sortBy) < minmax) Case 4 mark = (theFiles(j)(sortBy) > minmax) End Select If mark Then minmax = theFiles(j)(sortBy) minmaxSlot = j End If Next If minmaxSlot <> i Then temp = theFiles(minmaxSlot) theFiles(minmaxSlot) = theFiles(i) theFiles(i) = temp End If Next " 结束 %> <FORM Name="doSort" Method="Get"> <INPUT Type=Hidden Name=priorSort Value="<% = priorSort %>"> <INPUT Type=Hidden Name=sortBy Value="-1"> </FORM> <SCRIPT Language="JavaScript"> function reSort(which) { document.doSort.sortBy.value = which; document.doSort.submit(); } </SCRIPT> <CENTER> <FONT Size="+2"> 显示<% = (fileCount+1) %> 该目录下的文件<% = path %> </FONT> <P> 单击排序,再点一次反向排序 <P> <TABLE Border=1 CellPadding=3> <TR> <TH><A HREF="javascript:reSort(0);">文件名</A></TH> <TH><A HREF="javascript:reSort(1);">扩展名</A></TH> <TH><A HREF="javascript:reSort(2);">类型</A></TH> <TH><A HREF="javascript:reSort(3);">大小</A></TH> <TH><A HREF="javascript:reSort(4);">建立时间</A></TH> <TH><A HREF="javascript:reSort(5);">上次修改时间</A></TH> <TH><A HREF="javascript:reSort(6);">上次存取时间</A></TH> </TR> <% For i = 0 To fileCount Response.Write "<TR>" & vbNewLine For j = 0 To UBound(theFiles(i)) Response.Write " <TD>" & theFiles(i)(j) & "</TD>" & vbNewLine Next Response.Write "</TR>" & vbNewLine Next %> </TABLE> </BODY> </HTML> |
声明:本页内容由湖南景煌网络通过网络收集编辑所得,所有资料仅供用户参考;本站不拥有所有权,也不承认相关法律责任。如您认为本网页中有涉嫌抄写的内容,请及时与我们联系进行举报,并提供相关证据,工作人员会在5个工作日内联系您,一经查实,本站将立刻删除涉嫌侵权内容。如果您对网站优化核心技术文章感兴趣,请点击查看网站建设和网站推广的相关文章,请关注湖南景煌网络官网(www.0731jianzhan.com)
全国7x24小时客服热线
50倍赔付终端服务时间
部分产品可享受15天无理由退款
全国多家分公司便捷服务
持续陪伴企业成长,共创,共赢
帮助企业建设全网营销生态链
让企业与用户快速连接一切
为企业与用户搭建共享开发平台