① ASP遍历文件问题
<%sub bianli(path) dim fso dim objFolder dim objsubFolder dim objFile set fso=server.CreateObject("scripting.filesystemobject") on error resume next set objFolder=fso.GetFolder(path) for each objFile in objFolder.Files Response.Write path & "\\" & objFile.name & "<br>—" next Response.Write "<p>" for each objSubFolder in objFolder.Subfolders nowpath=path & "\\" & objSubFolder.name Response.Write nowpath & "<br>" bianli nowpath next set objFolder=nothing set fso=nothingend subbianli "D:\shuaigua\56bohai"%>看明白没有?你要先显示当前文件夹(注意当前)中的文件集合,再遍历文件夹中的子文件夹集合。而你的做法则是显示子文件夹(注意子字)中的文件集合,再去遍历子文件夹集合,这样的话一开始的那个文件夹(即D:\shuaigua\56bohai)的文件就无法显示了!
② asp遍历某目录下的所有文件夹和文件,分页显示
由于是从我程序里提取出来的,代码里可能有些没用的东西,你自己修改一下。<%@ LANGUAGE = VBScript CodePage = 936%><%Option ExplicitResponse.Buffer = Truedim MaxPerPage,MyPathdim CurrentPage,PageCounts,FolderCounts,path,goparent,pathurl,s_folderpathdim obj_fso,obj_folder,s_folderdim cname,enamedim bgMaxPerPage=20MyPath="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="/"&pathend ifIf CurrentPage<>"" And isNumeric(CurrentPage) Then CurrentPage=Cint(CurrentPage)Else CurrentPage=1End Ifif path="/" then goparent="根目录"else goparent="<a href=""?path="&server.urlencode(left(path,instrrev(path,"/",len(path)-1)))&""">返回上级目录"end ifpathurl=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=nothingelse%><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 ifset 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 functionFunction GetFileName(lpFullFileName) Dim nDotPos If InStr(lpFullFileName,".")=0 Then GetFileName=lpFullFileName Exit Function End If nDotPos=InStrRev(lpFullFileName,".") GetFileName=Left(lpFullFileName,nDotPos-1)End FunctionFunction 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 ifEnd function%>=============================================刚刚在实际应用中写了个这样的程序,代码在办公室。
③ ASP 遍历文件名到数组,想把数组倒过来。
For I = Ubound(fileArray) to Lbound(fileArray) step -1Response.Write fileArray(I) Next
④ 一个asp遍历文件夹的问题
那些格式的文件打不开,可能你电脑没有相应打开的软件吧,找找再安装上那些相应的软件,一样也可以打开的。。 估计是你自己电脑的软件匹配问题了,因为我试过你的代码是可以的。。。
⑤ asp中文件夹遍历降序排列的问题
把名称放在数组里,然后倒着读出来
⑥ 如何用ASP遍历文件夹,并显示每个文件的大小
问题可能出在nowpath=path + "\" + objSubFolder.name你应该先判断path是否带"\"这个了iif(right(path,1)="\",path,path&"\")然后,你需要将所有的"\"换成"/",这里用replace应为你的getRemoteFileSize函数里面用的是MSXML2.XMLHTTP,他支持打开一个远程http地址,所以你发送的应该是一个网络路径而不是本地路径!其中这两点最重要的区别就是"/"和"\"的区别了,然后就是域名的区别!所以你要先reponse wjsize出来看看值是不是一个有效地网址才可以!
⑦ ASP.NET如何遍历服务器端文件夹内的文件然后绑定数据库
这个不是用sql来搞定的吧。
个人感觉应该用服务器端代码来实现。
DirectoryInfodirInfo=newDirectoryInfo("路径");//参数一版:文件类型(如果所有文权件就是*)//参数二:是否查找目录下的子目录FileSystemInfo[]files=dirInfo.GetFileSystemInfos("*.jpg",DirectoryInfo.GetFileSystemInfos);DataGrid.DataSource=files;DataGrid1.DataBind();//剩下的,你只要前台把文件的个个属性对应上就可以了。FileSystemInfo类有哪些属性,建议去msdn上面查一下。
⑧ ASP.NET 中如何遍历一个文件夹下的所有文件,并用md5函数算出所有文件的md5值
不知道你解决没解决,我刚上传了一个你自己去下载吧,不过上传的是winFrom版,主要代码都是共有的有注释,有问题在问我把:http://download.csdn.net/detail/qq_17242011/8996873
⑨ asp.net(c#)遍历FTP下的文件夹、子文件夹、文件、子文件夹文件
递归//所有文件信息 string fileInfo = string.Empty; private void GetAllFiles() { if (folderBrowserDialog.ShowDialog() == DialogResult.OK) { DirectoryInfo dInfo = new DirectoryInfo(folderBrowserDialog.SelectedPath); //遍历该文件夹 GetFolder(dInfo); } using (System.IO.StreamWriter sw = new StreamWriter (Environment.GetFolderPath(Environment.SpecialFolder.Desktop)+"\\fileInfo.txt",false, Encoding.GetEncoding("gb2312"))) { sw.Write(fileInfo); sw.Flush(); } } private void GetFolder(DirectoryInfo dInfo) { //显示其中文件 GetFile(dInfo); //遍历文件夹中的文件夹 foreach (DirectoryInfo dir in dInfo.GetDirectories()) { //递归遍历该文件夹 GetFolder(dir); } } private void GetFile(DirectoryInfo dInfo) { //遍历文件夹中的文件 foreach (FileInfo file in dInfo.GetFiles()) { if(file.Extension.Equal(".jpg")||file.Extension.Equal(".gif")||file.Extension.Equal(".bmp")) { //这里就获取到了 fileInfo+=file.Name+"\r\n"; } Application.DoEvents(); } }
⑩ 【急】asp 遍历根目录“/”下所有文件夹和文件
你可以查下FSO例子大全,会有很多的代码,帮你写没用,自己学会修改才是真理