action_list.asp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <!--#include file="ASPJson.class.asp"-->
  2. <!--#include file="config_loader.asp"-->
  3. <%
  4. listTemplateName = Session.Value("ueditor_asp_listTemplateName")
  5. start = CInt(Request.Item("start"))
  6. size = CInt(Request.Item("size"))
  7. total = 0
  8. If size < 0 Then
  9. size = CInt(config.Item( listTemplateName + "ManagerListSize" ))
  10. End If
  11. path = config.Item( listTemplateName + "ManagerListPath" )
  12. Set extensions = config.Item( listTemplateName + "ManagerAllowFiles")
  13. Set list = new ASPJson.Collection
  14. Set fso = Server.CreateObject("Scripting.FileSystemObject")
  15. If fso.FolderExists(Server.MapPath(path)) = False Then
  16. state = "找不到目录:" + path
  17. Else
  18. Set all = ListAllFilesInFolder( fso, path )
  19. total = all.Count
  20. index = 0
  21. For Each file in all
  22. If index >= start And index < start + size Then
  23. Dim fileObject
  24. Set fileObject = new ASPJson.Collection
  25. fileObject.Add "url", file
  26. list.Add index - start, fileObject
  27. End If
  28. index = index + 1
  29. Next
  30. state = "SUCCESS"
  31. End If
  32. Set json = new ASPJson
  33. With json.data
  34. .Add "state", state
  35. .Add "list", list
  36. .Add "start", start
  37. .Add "size", size
  38. .Add "total", total
  39. End With
  40. json.PrintJson()
  41. Function ListAllFilesInFolder( fso, path )
  42. Dim list
  43. Set list = Server.CreateObject("Scripting.Dictionary")
  44. Set folder = fso.GetFolder(Server.MapPath(path))
  45. For Each file In folder.Files
  46. If CheckExt(file.Name) Then
  47. list.Add path & "/" & file.Name, true
  48. End If
  49. Next
  50. For Each subFolder In folder.SubFolders
  51. Set subList = ListAllFilesInFolder( fso, path & "/" & subFolder.Name )
  52. For Each subListFile In subList
  53. list.Add subListFile, true
  54. Next
  55. Next
  56. Set ListAllFilesInFolder = list
  57. End Function
  58. Function CheckExt( filename )
  59. For Each ext In extensions
  60. If UCase(GetExt(filename)) = UCase(extensions.Item(ext)) Then
  61. CheckExt = true
  62. Exit Function
  63. End If
  64. Next
  65. CheckExt = false
  66. End Function
  67. Function GetExt( file )
  68. GetExt = Right( file, Len(file) - InStrRev(file, ".") + 1 )
  69. End Function
  70. %>