導航:首頁 > 版本升級 > asp列出文件

asp列出文件

發布時間:2024-10-03 07:22:48

㈠ 如何用asp獲取指定文件夾下面的所有文件信息

利用FSO可以做到 但是你要注意文件夾的許可權設置
<%
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 '所有文件付給數組
response.write "<table width=100% border=0><tr>"
response.write "<td>文件名</td>"
response.write "<td>文件屬性</td>"
response.write "<td>文件大小</td>"
response.write "<td>更新日期</td></tr>"

for each objfoldercount in objfolder.subfolders '循環顯示文件夾

response.write "<tr><td><a href=?path="&objfoldercount.name&" target=""_blank"">"&objfoldercount.name&"</td>" '文件夾名稱
response.write "<td>"&objfoldercount.type&"</td>" '文件夾屬性
response.write "<td> </td>"

'文件夾大小
response.write "<td>"&objfoldercount.DateCreated&"</td>" '時間
next

for each objfileitem in objfoldercontents '循環
response.write "<tr><td><a href="&objfileitem.name&">"&objfileitem.name&"</a></td>"

'文件名
response.write "<td>"&objfileitem.type&"</td>" '類型
response.write "<td>"&objfileitem.size&"k</td>" '文件大小
response.write "<td>"&objfileitem.datelastmodified&"</td></tr>" '更新日期
next
response.write "</table>"
%>

㈡ asp列出文件

<%
Dim sPath, oFso, oFout, File
sPath = "plugin/"
Set oFso = Server.CreateObject("Scripting.FileSystemObject")
Set oFout = oFso.GetFolder(Server.Mappath(sPath))
Response.Write "<table border='1' cellspacing='0' cellpadding='0' align='center'>" & _
"<tr align='center'>" & _
"<td>文件名稱</td>" & _
"<td>文件短路握掘徑名</td>" & _
"<td>文空皮晌件物理地址</td>" & _
"<td>文件屬性</td>" & _
"<td>文件大小</td>" & _
"<td>文件類型</td>" & _
"<td>文件創建時間</td>" & _
"<td>最近訪問時間</td>" & _
"<td>最近修改時間</td>" & _
"</tr>"
For Each File In oFout.Files
Response.Write "<tr>" & _
"<斗鋒td>" & File.Name & "</td>" & _
"<td>" & File.ShortPath & "</td>" & _
"<td>" & File.Path & "</td>" & _
"<td>" & File.Attributes & "(" & SenFe_Attributes(File.Attributes) & ")</td>" & _
"<td>" & File.Size & "</td>" & _
"<td>" & File.Type & "</td>" & _
"<td>" & File.DateCreated & "</td>" & _
"<td>" & File.DateLastAccessed & "</td>" & _
"<td>" & File.DateLastModified & "</td>" & _
"</tr>"
Next
Response.Write "</table>"
Set oFout = Nothing
Set oFso = Nothing
Function SenFe_Attributes(iType)
Select Case iType
Case 0 SenFe_Attributes = "Normal-普通文件, 沒有設置任何屬性."
Case 1 SenFe_Attributes = "ReadOnly-只讀文件,可讀寫."
Case 2 SenFe_Attributes = "Hidden-隱藏文件,可讀寫."
Case 4 SenFe_Attributes = "System-系統文件,可讀寫."
Case 16 SenFe_Attributes = "Directory-文件夾或目錄,只讀."
Case 32 SenFe_Attributes = "Archive-上次備份後已更改的文件,可讀寫."
Case 1024 SenFe_Attributes = "Alias-鏈接或快捷方式,只讀."
Case 2048 SenFe_Attributes = "Compressed-壓縮文件,只讀."
End Select
End Function
%>

㈢ 利用ASP如何列出文件夾里所有文件和文件夾

使用fso對象,可以列出所有文件和文件夾.
以下的鉛野隱程序是我自己學ASP時寫的,除了這個文件外,還有of,ol兩個文件分別槐廳是來處理文件夾和文件.你可以參考一下.<%str="D:\"Set fs = CreateObject("Scripting.FileSystemObject")
set folder=fs.getfolder(str)
set folders=folder.SubFolders
for each item in folders%><a href="ol.asp?a=<%=server.URLEncode(str&item.name)&"\"%>"><%=item.name%></a><BR><%next%><BR><BR>以下脊皮是文件:<BR><%for each item in files%><a href="of.asp?b=<%=server.URLEncode(str&item.name)%>"><%=item.name%></a><BR><%next%>

㈣ 怎樣通過ASP查看一個文件夾里所有的文件 並自動顯示在文本框里

臨時幫你寫了一個 呵呵 好好學習
<%
set fso=createobject("scripting.filesystemobject")'創建FSO
Set f=fso.GetFolder(server.mappath("./"))'當前文件夾下的二級文件夾
set objSubFolders=f.Subfolders '獲取文版件夾容器
for each d in objSubFolders '循環文件夾開權始
set f1=d.files '獲取某一文件夾中的文件容器
for each e in f1 '循環文件開始
response.write d.Name&"/"&e.Name &"<br>"'輸出文件路徑
next'循環文件結束
next'循環文件夾結束
set fso=nothing'銷毀FSO
%>

㈤ ASP對指定文件夾內文件列表顯示

<%
'遞歸演算法簡單示例,遞歸遍歷指定目錄下所有文件和子目錄中的文件;
'可以自由引用或修改本代碼,但請保留連接或此注釋;

dir="/" '請設置你要顯示的目錄,"/"為整站所有文件,"../"為上級目錄下所有文件
set fso = createobject("scripting.filesystemobject")
response.write "指定目錄下所有文件及所有子目錄下文件顯示如下:" & "<br>"
iterate(server.mappath(dir))
function iterate(path)
dim folder, folders, files, file
set folder = fso.getfolder(path)
set files = folder.files
for each file in files
response.write file.path & "<br>"
next
set folders = folder.subfolders
for each f in folders
iterate f.path
next
end function
set fso=nothing
%>

㈥ asp遍歷某目錄下的所有文件夾和文件,分頁顯示

由於是從我程序里提取出來的,代碼里可能有些沒用的東西,你自己修改一下。
<%@ LANGUAGE = VBScript CodePage = 936%>
<%
Option Explicit
Response.Buffer = True
dim MaxPerPage,MyPath
dim CurrentPage,PageCounts,FolderCounts,path,goparent,pathurl,s_folderpath
dim obj_fso,obj_folder,s_folder
dim cname,ename
dim bg
MaxPerPage=20
MyPath="e:\音樂"
path=trim(request.querystring("path"))
CurrentPage=trim(request.querystring("page"))
if path="" or instr(path," ")>0 or instr(path,vbcrlf)>0 or instr(path,":")>0 or instr(path,"\")>0 then
path="/"
elseif right(path,1)<>"/" then
path=path&"/"
elseif left(path,1)<>"/" then
path="/"&path
end if

If CurrentPage<>"" And isNumeric(CurrentPage) Then
CurrentPage=Cint(CurrentPage)
Else
CurrentPage=1
End If
if path="/" then
goparent="根目錄"
else
goparent="<a href=""?path="&server.urlencode(left(path,instrrev(path,"/",len(path)-1)))&""">返回上級目錄"
end if
pathurl=server.urlencode(path)
's_folderpath=server.mappath(path)
s_folderpath=MyPath&replace(path,"/","\")
set obj_fso=server.createobject("scripting.filesystemobject")
%>
<html>
<head>
<title>文件管理</title>
<meta http-equiv="Content-Type" content="text/html;charset=gb2312">
<link rel="stylesheet" href="inc/style.css" type="text/css">
<head>
<body topmargin=0 leftmargin=3 rightmargin=3>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#E3EBF9">
<tr>
<td height="28"> 當前位置:<%=path%></td>
</tr>
</table><%
if obj_fso.folderexists(s_folderpath) then
%>
<table width="100%" border=0 cellpadding=0 cellspacing=0 bgcolor="#FFFFFF">
<tr>
<td width="258" valign="top">
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#C8D6F0">
<tr height="28">
<td><b><%=goparent%></b></td>
</tr>
</table>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#E8F1FF" style="table-layout:fixed;"><%
dim s_classname,s_classpath,s_classurl
dim i
i=1
FolderCounts=0
set obj_folder=obj_fso.getfolder(s_folderpath)
for each s_folder in obj_folder.subfolders
s_classname=s_folder.name
s_classpath=path&s_classname
s_classurl=server.urlencode(s_classpath)
if FolderCounts mod 2=0 then
bg=" bgcolor='#ffffff'"
else
bg=""
end if
%>
<tr height="22" align="center"<%=bg%>>
<td align="left" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;"><a href="?path=<%=pathurl&server.urlencode(s_classname)%>" title="進入子目錄「<%=s_classname%>」"><%=s_classname%></a></td>
</tr><%
FolderCounts=FolderCounts+1
i=i+1
next
%>
<tr>
<td height=22 bgcolor="#C8D6F0">本目錄共有<b><%=FolderCounts%></b>個子目錄。</td>
</tr>
</form>
</table>
</td>
<td width="5"></td>
<td height="100%" valign="top">
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#E8F1FF">
<tr height="28" bgcolor="#C8D6F0" align="center">
<td width="38%"><b>文件名</b></td>
<td width="9%"><b>文件大小</b></td>
<td width="20%"><b>最後修改時間</b></td>
</tr><%
dim startnum,TotleSize,s_file,s_filename,FileCounts,FileName,FileExt,s_pathurl
i=1
startnum=(CurrentPage-1)*MaxPerPage
TotleSize=0
for each s_file in obj_folder.files
FileCounts=FileCounts+1
next
if FileCounts mod MaxPerPage=0 then
PageCounts=FileCounts\MaxPerPage
else
PageCounts=FileCounts\MaxPerPage+1
end if
If CurrentPage<1 Then
CurrentPage=1
End If
if CurrentPage>PageCounts then
CurrentPage=PageCounts
end if
for each s_file in obj_folder.files
s_filename=s_file.name
s_pathurl=server.urlencode(path&s_filename)
if (i-1) mod 2=0 then
bg=" bgcolor='#ffffff'"
else
bg=""
end if
FileName=GetFileName(s_filename)
FileExt=GetFileExt(s_filename)
if i>startnum then
TotleSize=TotleSize+s_File.Size
%>
<tr height="22" align="center"<%=bg%>>
<td align="left"><%=s_file.name%></td>
<td><%=ByteNum(s_file.size)%></td>
<td><%=s_file.datelastmodified%></td>
</tr><%
end if
if i>startnum+MaxPerPage then
exit for
end if
i=i+1
next
%>
<tr>
<td height="22" colspan=3 align=right bgcolor="#C8D6F0"><%
if CurrentPage>1 then
response.write "<a href='?path="&pathurl&"&page="&(CurrentPage-1)&"'>上一頁</a> "
end if
response.write "本目錄共有"&obj_folder.files.count&"個文件 本頁文件為"&ByteNum(TotleSize)&"B 當前第 "
response.write "<select name='jtp' style='line-height:12px;border:none;height:12px;padding:0' onchange="&chr(34)&"window.location.href='?page='+(this.options.selectedIndex+1)+'&path="&pathurl&"'"&chr(34)&">"&vbcrlf
for i=1 to PageCounts
if i=CurrentPage then
response.write "<option selected>"&i&vbcrlf
else
response.write "<option>"&i&vbcrlf
end if
next
response.write "</select> 頁 共"&PageCounts&"頁"
if CurrentPage<PageCounts then
response.write "<a href='?path="&pathurl&"&page="&(CurrentPage+1)&"'>下一頁</a>"
end if
%>
</td>
</tr>
<tr>
<td height="100%" colspan=3 bgcolor="#F8FAFE"></td>
</tr>
</form>
</table>
</td>
</tr>
</table><%
set obj_folder=nothing
else
%>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#E8F1FF">
<tr>
<td height="80" align="center" bgcolor="#FFFFFF" style="color:#ff3333;font-weight:600">目錄不存在!</td>
</tr>
</table><%
end if
set obj_fso=nothing
%>
</center>
</body>
</html><%
function getname(s_string,s_clipchar)
n_strpos=instrrev(s_string,s_clipchar)
getname=lcase(right(s_string,len(s_string)-n_strpos))
end function
Function GetFileName(lpFullFileName)
Dim nDotPos
If InStr(lpFullFileName,".")=0 Then
GetFileName=lpFullFileName
Exit Function
End If
nDotPos=InStrRev(lpFullFileName,".")
GetFileName=Left(lpFullFileName,nDotPos-1)
End Function
Function GetFileExt(lpFullFileName)
Dim fnArray
If InStr(lpFullFileName,".")=0 Then
Exit Function
End If
fnArray=Split(lpFullFileName,".")
GetFileExt=fnArray(UBound(fnArray))
End Function
'--------格式文件尺寸顯示
Function ByteNum(num)
if Num=0 then
ByteNum="0K"
elseif Num<1024 then
ByteNum="1K"
else
ByteNum=formatNumber(int(Num/1024),0)&"K"
end if
' ByteNum=Num&" Byte"
'elseif Num<1048576 then
' ByteNum=formatNumber(int(Num/1024),0)&" KB"
'elseif Num<1073374812 then
' ByteNum=formatNumber(int(Num/1048576),0)&" MB"
'elseif Num<1073374812 then
'else
' ByteNum=formatNumber(int(Num/1073374812),0)&" GB"
'end if
End function
%>
=============================================
剛剛在實際應用中寫了個這樣的程序,代碼在辦公室。

㈦ 利用ASP如何列出文件夾里所有文件和文件夾

以下的程序是我自己學ASP時寫的,除了這個文件外,還有of,ol兩個文件分回別是來處理文件夾和文件.你可以答參考一下.<%str="D:\"Set fs = CreateObject("Scripting.FileSystemObject") set folder=fs.getfolder(str) a=<%=server.URLEncode(str&item.name)&"\"%>"><%=item.name%></a><BR><%next%><BR><BR>以下是文件:<BR><%for each item in files%><a href="of.asp?

閱讀全文

與asp列出文件相關的資料

熱點內容
ps入門必備文件 瀏覽:348
以前的相親網站怎麼沒有了 瀏覽:15
蘋果6耳機聽歌有滋滋聲 瀏覽:768
怎麼徹底刪除linux文件 瀏覽:379
編程中字體的顏色是什麼意思 瀏覽:534
網站關鍵詞多少個字元 瀏覽:917
匯川am系列用什麼編程 瀏覽:41
筆記本win10我的電腦在哪裡打開攝像頭 瀏覽:827
醫院單位基本工資去哪個app查詢 瀏覽:18
css源碼應該用什麼文件 瀏覽:915
編程ts是什麼意思呢 瀏覽:509
c盤cad佔用空間的文件 瀏覽:89
不銹鋼大小頭模具如何編程 瀏覽:972
什麼格式的配置文件比較主流 瀏覽:984
增加目錄word 瀏覽:5
提取不相鄰兩列數據如何做圖表 瀏覽:45
r9s支持的網路制式 瀏覽:633
什麼是提交事務的編程 瀏覽:237
win10打字卡住 瀏覽:774
linux普通用戶關機 瀏覽:114

友情鏈接