如果制作一个网页让它实现遍历服务器上某个文件夹的所有文件?

2025-04-04 04:29:04
推荐回答(1个)
回答1:

'以下内容复制保存入file.asp文件
<%
'删除文件处理过程,传递文件相对路径
Sub DeleFile(FilePath)
Set Del=Server.CreateObject("Scripting.FileSystemObject")
If Err <> 0 Then
Response.Write ""
Err.clear
Else
If InStr(FilePath,", ") > 0 then
Msg=""
FilePath=Split(FilePath,", ")
For i = 0 to ubound(FilePath)
If Del.FileExists(Server.MapPath(FilePath(i)))=True Then
Del.DeleteFile Server.MapPath(FilePath(i)),True
Else Msg=Msg&"\n文件"&FilePath(i)&"不存在!"
End If
Next
Response.Write ""
Else
If Del.FileExists(Server.MapPath(FilePath))=True Then
Del.DeleteFile Server.MapPath(FilePath),True
Response.Write ""
Else Response.Write ""
End If
End If
End If
Set Del=Nothing
End Sub

'删除文件夹过程,传递文件夹相对路径
Sub DeleFolder(FolderPath)
Set Del=Server.CreateObject("Scripting.FileSystemObject")
If Err <> 0 Then
Response.Write ""
Err.clear
Else
If Del.FolderExists(Server.MapPath(FolderPath))=True Then
Del.DeleteFolder Server.MapPath(FolderPath),True
Response.Write ""
Else Response.Write ""
End If
End If
Set Del=Nothing
End Sub
%>
<%
'创建文件操作对象
FLRoot="upload/"'定义管理文件根目录
FLPath=Request("FLPath")
FFPath = Server.MapPath(FLRoot&FLPath)
IF Len(FFPath)=2 then FFPath=FFPath&"\" End If
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
If objFSO.FolderExists(FFPath) Then
Response.write "

文件夹 "&FLRoot&FLPath&" 下的所有文件:

"
Set objFolder = objFSO.GetFolder(FFPath)
set objSubFolders=objFolder.Subfolders
Else
Response.Write ""
End If
%>
<%
FilePath=Request("FilePath")
FolderPath=Request("FolderPath")
If InStr(FilePath,".asp")>0 or InStr(FilePath,"../")>0 or InStr(FilePath,"..\") >0 Then
Response.Write ""
Else
If FilePath<>"" Then
DeleFile(FilePath)
End If
End If
If InStr(FolderPath,"../")>0 or InStr(FolderPath,"..\") >0 Then
Response.Write ""
Else
If FolderPath<>"" Then
DeleFolder(FolderPath)
End If
End If
%>




文件管理








<%If Len(FFPath)<>3 and 0 then%>
上级目录

<%End If%>
后退
刷新

<%For Each objSubFolder in objSubFolders%>
删除|<%=objSubFolder.Name%>

<%Next%>
<%For Each objFile in objFolder.Files%>

<%=objFile.Name%>

<%Next%>






<%
'关闭文件操作对象
Set objFolder = Nothing
Set objFSO = Nothing
%>