如何用FSO对象列出文件夹下的所有文件名称和文件夹?

darker 2003-08-19 08:59:35
或是用JS脚本或其它,列出给定目录下的所有文件名称和子文件夹名称?
...全文
126 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
czylz 2003-08-19
  • 打赏
  • 举报
回复
up
friendxu 2003-08-19
  • 打赏
  • 举报
回复
已经很全了,有vbscript,javascript。可自行选择,自由发挥!
GHOSTWY 2003-08-19
  • 打赏
  • 举报
回复
<%@ LANGUAGE="VBSCRIPT" %>
<% Option Explicit %>
<HTML>
<HEAD> <TITLE>文件浏览器</TITLE> </HEAD>
<BODY>
<TABLE width="100%" border=1 bordercolor="#000000" align="left" cellpadding="2" cellspacing="0">
<TR align="left" valign="top" bgcolor="#800000" >
<TD width="60%"><FONT color="#ffffff"><B><FONT size="2" face="宋体">文件名</FONT></B></FONT></TD>
<TD width="15%"><FONT color="#ffffff"><B><FONT size="2" face="宋体">大小</FONT></B></FONT></TD>
<TD width="25%"><FONT color="#ffffff"><B><FONT size="2" face="宋体">修改日期</FONT></B></FONT></TD>
</TR>
<%
Dim objFSO
Dim objFile
Dim objFolder
Dim sMapPath
dim i
i=0
Set objFSO = CreateObject("Scripting.FileSystemObject")
sMapPath ="E:\asp" '修改为你的目录
Set objFolder = objFSO.GetFolder(sMapPath)
response.Write(objFolder.DateLastModified)
For Each objFile In objFolder.Files
%>
<TR align="left" valign="top" bordercolor="#999999" bgcolor='f7efde'>
<TD> <FONT size="2" face="宋体" color="#000000"><A href="<% = sMapPath & "/" & objFile.Name %>">
<%
i=i+1
Response.Write objFile.Name
%>
</A>
</FONT>
</TD>
<TD>
<FONT size="2" face="宋体" color="#000000">
<%
If objFile.Size <1024 Then
Response.Write objFile.Size & " Bytes"
ElseIf objFile.Size < 1048576 Then
Response.Write Round(objFile.Size / 1024.1) & " KB"
Else
Response.Write Round((objFile.Size/1024)/1024.1) & " MB"
End If
%>
</FONT>
</TD>
<TD>
<FONT size="2" face="宋体" color="#000000">
<%
Response.Write objFile.DateLastModified
%>
</FONT>
</TD>
</FONT>
</TD>
</TR>
<%
Next
if i=0 then response.Write("NO files!")
%>
</TABLE>
</BODY>
</HTML>
anita2li 2003-08-19
  • 打赏
  • 举报
回复
Dim fso, f, f1, s, sf
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(folderspec)
Set sf = f.SubFolders
For Each f1 in sf
s = s & f1.name
s = s & "<BR>"
Next
Dim fso, f, f1, fc, s
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(folderspec)
Set fc = f.Files
For Each f1 in fc
s = s & f1.name
s = s & "<BR>"
Next
iceriver521 2003-08-19
  • 打赏
  • 举报
回复
OK
MyLearn 2003-08-19
  • 打赏
  • 举报
回复
function JavaBianli(path)
{
pathFolderArr = new Array();
pathFileArr = new Array();
fso = Server.CreateObject('Scripting.FileSystemObject');
objFolder = fso.GetFolder(path); //创建文件夹对象
var enmFolders = new Enumerator(objFolder.SubFolders); //创建的子文件夹对象
pathFolderArr[0] = path;
for (var i = 1; !enmFolders.atEnd(); enmFolders.moveNext(), i++)
{
objSubFolder = enmFolders.item();
nowpath = path + '\\' + objSubFolder.Name;
pathFolderArr[i] = nowpath;
Response.Write(pathFolderArr[i]);
Response.Write('<br>');
var enmFiles = new Enumerator(objFolder.Files);
for (; !enmFiles.atEnd(); enmFiles.moveNext())
{
objFile = enmFiles.item();
pathFileArr[i] = nowpath + '\\' + objFile.Name;
Response.Write(pathFileArr[i]);
Response.Write('<br>');
}
JavaBianli(nowpath); //调用递归
}
}
JavaBianli('d:\\test')
Brookes 2003-08-19
  • 打赏
  • 举报
回复
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
' Get a reference to drive C
Set objDriveC = objFSO.GetDrive("C:")
' Get a reference to the root folder
Set objRoot = objDriveC.RootFolder
' Get a reference to the SubFolders collection
Set objFolders = objRoot.SubFolders
' Get a reference to the first folder in the SubFolders collection
For Each objFolder In objFolders
Set objFolder1 = objFolders.Item((objFolder.Name))
Exit For
Next
' Iterate through all the files in this folder
For Each objFile in objFolder1.Files
Response.Write "Name: " & objFile.Name & "   "
Response.Write "ShortName: " & objFile.ShortName & "   "
Response.Write "Size: " & objFile.Size & " bytes    "
Response.Write "Type: " & objFile.Type & "<BR>"
Response.Write "Path: " & objFile.Path & "   "
Response.Write "ShortPath: " & objFile.ShortPath & "<BR>"
Response.Write "Created: " & objFile.DateCreated & "   "
Response.Write "LastModified: " & objFile.DateLastModified & "<P>"
Next

28,390

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧