asp 顯示目錄所有檔案

來源:互聯網
上載者:User

option   explicit
dim   infopath                     '當前路徑  
dim   serverpath                 '伺服器路徑  
dim   objfso                         '檔案組件  
dim   objfile                       '檔案  
dim   objfolder                   '目錄  
dim   objfoldercontents   '所有檔案  
dim   objfoldercount         '臨時陣列變數-檔案夾  
dim   objfileitem               '臨時陣列變數-檔案

infopath=request.servervariables("path_info")       '得到檔案相對路徑  
serverpath=server.mappath(infopath)                                   '得到檔案絕對路徑  

set   objfso=createobject("scripting.filesystemobject")       '執行個體檔案組件  
set   objfile=objfso.getfile(serverpath)                                     '讀取檔案所在路徑  
set   objfolder=objfile.parentfolder                                             '根據檔案所在路徑得到上級目錄  

set   objfoldercontents=objfolder.files                                       '所有檔案付給數組    

for   each   objfileitem   in   objfoldercontents                               '迴圈  
response.write("http://www.111cn.net/" & objfileitem.name&"<br />")             '檔案名稱  
next  

'代碼二

set fso = server.createobject("scripting.filesystemobject")
if fso.folderexists(request("filepath")) then
set objfolder = fso.getfolder(request("filepath"))
 for each objfile in objfolder.files
             response.write objfile.name
         next
         set objfolder = nothing
set fso = nothing

'這樣可以顯示所有檔案,但不包括檔案夾
%>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.