获取文件夹列表、获取目录名称、文件列表、文件名称

使用fso获取文件夹列表
<%  
    function    
WriteChildFolderNames(folderPath)  
        dim     fso,    
fd  
        set     fso     =    
Server.CreateObject("Scripting.FileSystemObject")  
        set     fd    
=     fso.GetFolder(folderPath)  
        Response.Write    
"<br>目录     "     &     folderPath     &     "    
下的子目录:<hr>"  
        for     each     item     in    
fd.SubFolders  
            Response.Write     item.Name     &    
"<br>"  
        next  
        set     fd     =    
nothing  
        set     fso     =     nothing  
    end    
function  
   
    '调用范例:  
   
    '     当前目录的子目录列表  
   
WriteChildFolderNames(Server.MapPath("."))  
   
    '    
通过绝对路径来引用  
    WriteChildFolderNames("d:\")  
    %>


使用fso获取文件列表
<%  
   function   
ShowFiles(folderPath)  
   dim    fso,    fd  
   set    fso    =   
Server.CreateObject("Scripting.FileSystemObject")  
   set    fd    =   
fso.GetFolder(folderPath)  
   
   Response.Write    "<br>文件夹   
"    &    folderPath    &    "    下的文件列表:<hr>"  
   
  
Response.Write    "<select    multiple    size='10'>"  
   for   
each    f    in    fd.Files  
   Response.Write    "<option>"   
&    f.Name    &    "</option><br>"  
   next  
  
Response.Write    "</select>"  
   end    function  
   
  
'示例:  
   '通过绝对路径调用:  
   ShowFiles("d:\")  
  
ShowFiles("F:\downloads\mp3")  
   '通过相对路径调用  
  
ShowFiles(Server.MapPath("."))  
   %>

posted @ 2011-09-23 17:36  #i小龙#  阅读(833)  评论(0编辑  收藏  举报