asp读取指定目录下的文件名
2014-09-03 11:13
141 查看
bianli(Server.MapPath("/")+"\pic")
InStrRev("abcd.jpg", ".") 计算出abcd.jpg中第一次出现.所在的位置是第几个字符=5
mid("abcd.jpg",1,4) 取前四位abcd
mid("abcd.jpg",5) 从五位往后取(包括第五位) .jpg
取前缀abc
FullPath = "abc.jpg"
f = mid(FullPath,1,InStrRev(FullPath, ".")-1)
Response.Write f
娶后缀jpg
FullPath = "abc.jpg"
f = mid(FullPath,InStrRev(FullPath, ".")+1)
Response.Write f
<%
Set MyFileObject=Server.CreateObject("Scripting.FileSystemObject")'创建一个Folder对象
foldername=server.mappath("./")
Set MyFolder=MyFileObject.GetFolder(foldername)
i=0'循环显示其中文件夹
response.write "显示文件夹:"
For Each thing in MyFolder.subfolders
Response.Write("<br>"&thing)
i=i+1
Next
response.write "<br>共有"&i&"个文件夹"
response.write "<p>显示文件名"'循环显示其中文件
i=0
For Each thing in MyFolder.Files
Response.Write("<br>"&thing)
i=i+1
Next
response.write "<br>共有"&i&"个文件"
%>
<%
Set MyFileObject=Server.CreateObject("Scripting.FileSystemObject")'创建一个Folder对象
Set MyFolder=MyFileObject.GetFolder(server.mappath("."))
For Each thing in MyFolder.Files
thing=mid(thing,InStrRev(thing, "\")+1)
f = mid(thing,InStrRev(thing, ".")+1)
Set Reg = New RegExp
Reg.Pattern="test"
Set Matche=Reg.Execute(thing) '正则匹配Matches.Count<1表示不选;Matches.Count>1 就是匹配到选中
Reg.Pattern="lin"
Set Matches=Reg.Execute(thing)
IF Matches.Count<1 And Matche.Count<1 And f="asp" And thing<>"lin.asp" And thing<>"tpl.asp" And thing<>"tiao.asp" And thing<>"master.asp" And thing<>"delete.asp" Then
Response.Write thing
Response.Write("<br>")
End If
Next
%>
------------------------------------------------------------------------------------------------------------------------------------
生用的遍历文件:
<%@language="vbscript" codepage="65001"%>
<%
Response.Expires = 0
function bianli(path)
dim fso 'fso对象
dim objFolder '文件夹对象
dim objFiles '文件集合
dim objFile '文件对象
set fso=server.CreateObject("scripting.filesystemobject")
on error resume next
set objFolder=fso.GetFolder(path)'创建文件夹对象
set objSubFolders=objFolder.Subfolders'
for each objSubFolder in objSubFolders
nowpath=path + objSubFolder.name + "\"
Response.Write nowpath
set objFiles=objFolder.Files
for each objFile in objFiles
Response.Write (objFile.name)
Response.Write "<br/>"
Next
bianli(nowpath) '调用递归
next
set objFolder=nothing
set objSubFolders=nothing
set fso=nothing
end function
%>
<%
bianli(Server.MapPath("/") + "/new") '调用bianli()函数,这里是遍历当前目录下的new文件夹
%>
----------------------------------------------------------------------------------------------------
<%
Set fso=Server.CreateObject("Scripting.FileSystemObject")'创建一个Folder对象
fpath="."'Request.form("fpath")
set objfolder=fso.getfolder(server.mappath(fpath))
for each objsubfolder in objfolder.subfolders
Response.write "子文件夹名称:" & objsubfolder.name & "<br>"
next
Response.write "<br>"
for each objfile in objfolder.files
Response.write objfile.name & "<br>"
exitname=fso.GetExtensionName(objfile.name)'文件后缀也可以用这获取f = mid(thing,InStrRev(thing, ".")+1)'取asp后缀的文件 f="asp"
response.Write exitname & "<br>"
next
set objfolder=nothing
%>
-----------------------------------------------------------------------------------------
<%
Sub GetFolderObj(FD_getfolder)
For each SFolder in FD_getfolder.subfolders
call GetFileObj(SFolder)
call GetFolderObj(SFolder)
Next
End Sub
Sub GetFileObj(FD_getfile)
WritePath(FD_getfile)
For each MF in FD_getfile.files
call WriteFileMes(MF)
Next
End Sub
Sub WriteFileMes(MyFileObj)
%>
<tr bgcolor="#FFFFD0">
<td><%=MyFileObj.name%></td>
<td><%=MyFileObj.size%></td>
<td><%=MyFileObj.DateCreated %></td>
<td><%=MyFileObj.DateLastAccessed%></td>
<td><%=MyFileObj.DateLastModified%></td>
<td><%=MyFileObj.Type%></td>
</tr>
<%
End Sub
Sub WritePath(FDObj)
%>
<tr>
<td colspan="6" bgcolor="#81BDD3" ><%=FDObj.path%>下面的文件有:</td>
</tr>
<%
End Sub
Sub main()
Set fso =Server.CreateObject("Scripting.FileSystemObject")
Set PFD=fso.getfolder(server.MapPath("."))
Response.Write("<table>")
call GetFileObj(PFD)
call GetFolderObj(PFD)
Response.Write("</table>")
End sub
%>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>所有文件</title>
<style type="text/css">
<!--
td {
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
}
-->
</style>
</head>
<body>
<% call main() '调用主程序 %>
</body>
</html>
-----------------------------------------------------------------------------------------
InStrRev("abcd.jpg", ".") 计算出abcd.jpg中第一次出现.所在的位置是第几个字符=5
mid("abcd.jpg",1,4) 取前四位abcd
mid("abcd.jpg",5) 从五位往后取(包括第五位) .jpg
取前缀abc
FullPath = "abc.jpg"
f = mid(FullPath,1,InStrRev(FullPath, ".")-1)
Response.Write f
娶后缀jpg
FullPath = "abc.jpg"
f = mid(FullPath,InStrRev(FullPath, ".")+1)
Response.Write f
<%
Set MyFileObject=Server.CreateObject("Scripting.FileSystemObject")'创建一个Folder对象
foldername=server.mappath("./")
Set MyFolder=MyFileObject.GetFolder(foldername)
i=0'循环显示其中文件夹
response.write "显示文件夹:"
For Each thing in MyFolder.subfolders
Response.Write("<br>"&thing)
i=i+1
Next
response.write "<br>共有"&i&"个文件夹"
response.write "<p>显示文件名"'循环显示其中文件
i=0
For Each thing in MyFolder.Files
Response.Write("<br>"&thing)
i=i+1
Next
response.write "<br>共有"&i&"个文件"
%>
<%
Set MyFileObject=Server.CreateObject("Scripting.FileSystemObject")'创建一个Folder对象
Set MyFolder=MyFileObject.GetFolder(server.mappath("."))
For Each thing in MyFolder.Files
thing=mid(thing,InStrRev(thing, "\")+1)
f = mid(thing,InStrRev(thing, ".")+1)
Set Reg = New RegExp
Reg.Pattern="test"
Set Matche=Reg.Execute(thing) '正则匹配Matches.Count<1表示不选;Matches.Count>1 就是匹配到选中
Reg.Pattern="lin"
Set Matches=Reg.Execute(thing)
IF Matches.Count<1 And Matche.Count<1 And f="asp" And thing<>"lin.asp" And thing<>"tpl.asp" And thing<>"tiao.asp" And thing<>"master.asp" And thing<>"delete.asp" Then
Response.Write thing
Response.Write("<br>")
End If
Next
%>
------------------------------------------------------------------------------------------------------------------------------------
生用的遍历文件:
<%@language="vbscript" codepage="65001"%>
<%
Response.Expires = 0
function bianli(path)
dim fso 'fso对象
dim objFolder '文件夹对象
dim objFiles '文件集合
dim objFile '文件对象
set fso=server.CreateObject("scripting.filesystemobject")
on error resume next
set objFolder=fso.GetFolder(path)'创建文件夹对象
set objSubFolders=objFolder.Subfolders'
for each objSubFolder in objSubFolders
nowpath=path + objSubFolder.name + "\"
Response.Write nowpath
set objFiles=objFolder.Files
for each objFile in objFiles
Response.Write (objFile.name)
Response.Write "<br/>"
Next
bianli(nowpath) '调用递归
next
set objFolder=nothing
set objSubFolders=nothing
set fso=nothing
end function
%>
<%
bianli(Server.MapPath("/") + "/new") '调用bianli()函数,这里是遍历当前目录下的new文件夹
%>
----------------------------------------------------------------------------------------------------
<%
Set fso=Server.CreateObject("Scripting.FileSystemObject")'创建一个Folder对象
fpath="."'Request.form("fpath")
set objfolder=fso.getfolder(server.mappath(fpath))
for each objsubfolder in objfolder.subfolders
Response.write "子文件夹名称:" & objsubfolder.name & "<br>"
next
Response.write "<br>"
for each objfile in objfolder.files
Response.write objfile.name & "<br>"
exitname=fso.GetExtensionName(objfile.name)'文件后缀也可以用这获取f = mid(thing,InStrRev(thing, ".")+1)'取asp后缀的文件 f="asp"
response.Write exitname & "<br>"
next
set objfolder=nothing
%>
-----------------------------------------------------------------------------------------
<%
Sub GetFolderObj(FD_getfolder)
For each SFolder in FD_getfolder.subfolders
call GetFileObj(SFolder)
call GetFolderObj(SFolder)
Next
End Sub
Sub GetFileObj(FD_getfile)
WritePath(FD_getfile)
For each MF in FD_getfile.files
call WriteFileMes(MF)
Next
End Sub
Sub WriteFileMes(MyFileObj)
%>
<tr bgcolor="#FFFFD0">
<td><%=MyFileObj.name%></td>
<td><%=MyFileObj.size%></td>
<td><%=MyFileObj.DateCreated %></td>
<td><%=MyFileObj.DateLastAccessed%></td>
<td><%=MyFileObj.DateLastModified%></td>
<td><%=MyFileObj.Type%></td>
</tr>
<%
End Sub
Sub WritePath(FDObj)
%>
<tr>
<td colspan="6" bgcolor="#81BDD3" ><%=FDObj.path%>下面的文件有:</td>
</tr>
<%
End Sub
Sub main()
Set fso =Server.CreateObject("Scripting.FileSystemObject")
Set PFD=fso.getfolder(server.MapPath("."))
Response.Write("<table>")
call GetFileObj(PFD)
call GetFolderObj(PFD)
Response.Write("</table>")
End sub
%>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>所有文件</title>
<style type="text/css">
<!--
td {
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
}
-->
</style>
</head>
<body>
<% call main() '调用主程序 %>
</body>
</html>
-----------------------------------------------------------------------------------------
相关文章推荐
- linux下读取指定目录下的文件名,并进行排序
- Linux/Unix下读取指定目录下的所有文件名
- Linux/Unix下读取指定目录下的所有文件名
- cocos2d-x:读取指定目录下的文件名+解决中文乱码(win32下有效)
- Python 读取指定目录及其子目录下所有文件名
- php读取指定目录文件夹下所有文件名
- 指定文件名读取WEB-INFO目录下properties配置(windows平台)
- Java读取指定目录下的所有文件名
- java 读取目录及子目录下指定文件名的路径 并放到一个List数组里面返回遍历和写到文件里
- 读取指定目录下的所有文件名,并把它存储到本地
- linux c/c++ 读取指定目录下的文件名
- 分享下java 读取目录及子目录下指定文件名的路径 并放到一个List数组里面返回遍历和写到文件里
- Asp.net 获取指定目录下的后缀名为".doc" 的所有文件名和文件路径
- 分享下java 读取目录及子目录下指定文件名的路径 并放到一个List数组里面返回遍历和写
- 分享下java 读取目录及子目录下指定文件名的路径 并放到一个List数组里面返回遍历和写到文件里
- Asp.net 获取指定目录下的后缀名为".doc" 的所有文件名和文件路径
- Asp.Net 文件操作基类(读取,删除,批量拷贝,删除,写入,获取文件夹大小,文件属性,遍历目录)(一)
- Asp.Net 文件操作基类(读取,删除,批量拷贝,删除,写入,获取文件夹大小,文件属性,遍历目录)
- ASP检索网站指定目录文件的算法与应用方向
- [导入]Asp.Net 文件操作基类(读取,删除,批量拷贝,删除,写入,获取文件夹大小,文件属性,遍历目录)(一)