FSO操作文件系统

时间:2007-03-07 16:19:39   来源:  作者:  点击:次  出处:技术无忧
关键字:目录列表 FSO FTP


’FSO文件目录 
Function showallfile(path) 
’On Error Resume Next 
path=Replace(path,"//","/") 
set fso =  CreateObject("Scripting.FileSystemObject") 
Dim uploadPath,uploadfolder,objSubFolders,allfiles,fileitem,objSubFolder, 
sFileName 
 If InStr(1,path,":\")=0 Then  
 path=Replace(path,"\","/") 
 uploadPath = server.mappath(path) 
 Else 
 path=Replace(path,"/","\") 
 uploadPath=path 
 End If  
response.write(warn_red(uploadPath)) 
if not fso.folderexists(uploadPath) Then 
response.write warn_red("路径查找失败") 
Exit Function  
End If  
Set uploadfolder = fso.GetFolder(uploadPath) 
If uploadfolder.isrootfolder Then  
response.write("<b>根目录</b><br/>") 
Else 
response.write("<b><font color=""#00008b"">父目录:</font><a href=""default.asp?action=fso&this=top&path="&uploadfolder.parentfolder&"""> 
"&uploadfolder.parentfolder&" </a></b><br/>")  

End If  
response.write("<b>目录大小:"&int(uploadfolder.size/1024)&" KB</b><br/>")  
set objSubFolders=uploadfolder.Subfolders 
Dim fso_mes 
fso_mes="<ol>" 
for each objSubFolder in objSubFolders 
fso_mes=fso_mes& "<li><b><a href=""default.asp?action=fso&this=top&path="&path&"/"&objSubFolder.name&"""><font color=blue>" & objSubFolder.name & "</font></a></b></li>" 
next 
set allfiles = uploadfolder.Files 
for each fileitem in allfiles 
 fso_mes=fso_mes& "<li><a href=""default.asp?action=fso&this=file&path="&path&"/"&fileitem.Name&""">" & fileitem.Name & "</a></li>" 
Next 
fso_mes=fso_mes&"</ol>" 
response.write(fso_mes) 
response.write deltext(uploadPath,1) 
End Function 

  

’文件属性 
Function filepro(name) 
name=Replace(name,"//","/") 
Dim whichfile 
If InStr(1,name,":\")=0 Then  
name=Replace(name,"\","/") 
whichfile = server.mappath(name) 
Else 
name=Replace(name,"/","\") 
whichfile=name 
End If  
Set fso = CreateObject("Scripting.FileSystemObject") 
If Not fso.fileexists(whichfile) Then  
 response.write(warn_red("文件不存在或者无访问权限")) 
 Exit Function  
End If  
Dim f2,s_mess 
Set f2 = fso.GetFile(whichfile) 
s_mess = "<div class=""admin_post_form""><b><font color=""#00008b"">父目录:</font><a href=""default.asp?action=fso&this=top&path="&f2.parentfolder&""">"&f2.parentfolder& 
"</a></b><br/>" 
s_mess = s_mess & "文件名称:" & f2.name & "<br>" 
s_mess = s_mess & "文件短路径名:" & f2.shortPath & "<br>" 
s_mess = s_mess & "文件物理地址:" & f2.Path & "<br>" 
s_mess = s_mess & "文件属性:" & f2.Attributes & "<br>" 
s_mess = s_mess & "文件大小: " & f2.size & "<br>" 
s_mess = s_mess & "文件类型: " & f2.type & "<br>" 
s_mess = s_mess & "文件创建时间: " & f2.DateCreated & "<br>" 
s_mess = s_mess & "最近访问时间: " & f2.DateLastAccessed & "<br>" 
s_mess = s_mess & "最近修改时间: " & f2.DateLastModified&"<br/></div>" 
response.write(s_mess) 
If killint(Trim(request("type")),0,0,2)<>0 Then  
showtext(whichfile) 
End If  
response.write deltext(whichfile,0) 
End Function  
’ 
SUB showtext(files) 
 dim iStr,adosText,strasp 
 set adosText=Server.CreateObject("ADODB.Stream") 
 adosText.mode=3 
 adosText.type=2 
 adosText.charset="gb2312" 
 ’adosText.charset="big5" 
 adosText.open 
 If InStr(1,files,":\")=0 Then  
 files=Replace(files,"\","/") 
 files = server.mappath(files) 
 Else 
 files=Replace(files,"/","\") 
 files=files 
 End If  
 adosText.loadFromFile (files) 
 strasp=adosText.ReadText() 
 adosText.close 
 set adosText=nothing%> 
<form method="post" class="admin_post_form" action="default.asp?action=fso&this=edit&mode=1"> 
 <textarea id="txt" name="txt" rows="15" cols="60"><%=Server.HTMLEncode(strasp)%></textarea> 
<label> <input name="path" type="hidden" value="<%=Trim(request("path"))%>"/><input type="submit" name="okedit" class="submit" value="确定编辑"> </label> 
</form> 
<%End Sub 
Function deltext(file,mode) 
Dim deltext_mess 
deltext_mess="<div class=""deltext"">" 
Select Case killint(mode,0,0,2) 
Case 0: 
deltext_mess=deltext_mess&"文件操作:<a href=""default.asp?action=fso&this=file&path="&file&""">属性</a><a  onclick=""{if(confirm(’警告,非文本请不要读取,否则文件无法读取了,你坚持点击确定么?劝你点击取消’)){return true;} return false;}"" href=""default.asp?action=fso&this=file&path="&file&"&type=1""><font color=red><b>编辑</b></font></a><a href=""default.asp?action=fso&this=move&path="&file&""">移动</a><a href=""default.asp?action=fso&this=copy&path="&file&"&mode=0"">复制</a><a&nbsp;href=""default.asp?action=fso&this=rename&path="&file&"&mode=0"">重命名</a><a  onclick=""{if(confirm(’警告,删除操作不能恢复,小心使用!!!’)){return true;} return false;}"" href=""default.asp?action=fso&this=del&path="&file&"&mode=0""><font color=red><b>删除</b></font></a>" 

Case 1: 
deltext_mess=deltext_mess&"文件夹操作:<a href=""default.asp?action=fso&this=top&path="&file&""">列表</a><a href=""default.asp?action=fso&this=add&path="&file&"&ff=1"">创建目录</a><a href=""default.asp?action=fso&this=add&path="&file&""">手建文件</a><a href=""default.asp?action=fso&this=up&path="&file&""">上传文件</a><a href=""default.asp?action=fso&this=move&path="&file&"&mode=1"">移动</a><a href=""default.asp?action=fso&this=copy&path="&file&"&mode=1"">复制</a><a href=""default.asp?action=fso&this=rename&path="&file&"&mode=1"">重命名</a><a  onclick=""{if(confirm(’警告,删除操作不能恢复,以上列表的文件全部被删除,你坚持点击确定么?劝你点击取消’)){return true;} return false;}"" href=""default.asp?action=fso&this=del&path="&file&"&mode=1""><font color=red><b>删除</b></font></a>" 

End Select 
deltext_mess=deltext_mess&"</div>" 
deltext=deltext_mess 
End Function



 3/3   |‹ ‹‹ 1 2 3

文章评论

共有 0 位网友发表了评论 此处只显示部分留言 点击查看完整评论页面