您所在的位置:小祥子 » 编程 » ASP » 正文

ASP获取文件夹与文件列表方法

时间:2015-02-16 编辑:本站 来源:本站原创

'获取文件夹列表
Function getFolderList(Byval cDir)
 dim filePath,objFolder,obJSubFolder,objSubFolders,i
 i = 0
 redim  folderList(0)
 filePath = server.mapPath(cDir)
 set objFolder=objFso.GetFolder(filePath)
 set objSubFolders=objFolder.Subfolders
 for each objSubFolder in objSubFolders
  ReDim Preserve folderList(i)
  With objSubFolder
   folderList(i) = .name & ",文件夹," & .size/1000 & "k," & .DateLastModified & "," & cDir & "/" & .name
  End With
  i = i + 1
 next
 set objFolder=nothing
 set objSubFolders=nothing
 getFolderList = folderList
End Function
'获取文件列表
Function getFileList(Byval cDir)
 dim filePath,objFolder,objFile,objFiles,i
 i = 0
 redim  fileList(0)
 filePath = server.mapPath(cDir)
 set objFolder=objFso.GetFolder(filePath)
 set objFiles=objFolder.Files
 for each objFile in objFiles
  ReDim Preserve fileList(i)
  With objFile
   fileList(i) = .name & "," & Mid(.name, InStrRev(.name, ".") + 1) & "," & .size/1000 & "k," & .DateLastModified & "," & cDir & "/" & .name
  End With
  i = i + 1
 next
 set objFiles=nothing
 set objFolder=nothing
 getFileList = fileList
End Function