ASP获取文件所在文件夹名称、复制文件、创建、删除文件夹代码
分类:程序开发 Tags: asp 评论:0 浏览:4953 最近更新时间:2009/9/25 19:00:58
- <%
- '获取几级文件夹或文件名称
- arr=Split(Request.ServerVariables("SCRIPT_NAME"),"/")
- wenjianjia_name=arr(2)
- response.Write(wenjianjia_name&"<br />")
- '文件所在文件夹名称
- cur_URL = Server.MapPath(".")
- arr_curURL = split(cur_URL,"\")
- len_arr = ubound(arr_curURL)
- this_curURL= arr_curURL(len_arr)
- response.Write(this_curURL&"<br />")
- '文件名称
- cur_URL = Request.ServerVariables("url")
- arr_curURL = split(cur_URL,"/")
- len_arr = ubound(arr_curURL)
- this_curURL= arr_curURL(len_arr)
- response.Write(this_curURL&"<br />")
- folder="www.yuzhiguo.com"'需要创建的文件夹名称
- Call createfolder(folder)
- Function createfolder(folder)
- set fs=createobject("scripting.filesystemobject")
- url=server.mappath(folder)
- if Not fs.folderexists(url) then
- fs.createfolder(url)
- Response.write url&"创建成功!<br />"
- else
- Response.write url&"存在!<br />"
- end if
- End Function
- '-------------------复制文件--------
- TempSource= Server.MapPath("/yuzhiguo.jpg")'源文件
- TempEnd=Server.MapPath(folder&"/yuzhiguo.jpg")'移动目标地
- Call CopyFiles(TempSource,TempEnd)
- Function CopyFiles(TempSource,TempEnd)
- Dim FSO
- Set FSO = Server.CreateObject("Scripting.FileSystemObject")
- IF FSO.FileExists(TempEnd) then
- Response.Write "目标备份文件 <b>" & TempEnd & "</b> 已存在,请先删除!<br />"
- Set FSO=Nothing
- Exit Function
- End IF
- IF FSO.FileExists(TempSource) Then
- Else
- Response.Write "要复制的源数据文件 <b>"&TempSource&"</b> 不存在!<br />"
- Set FSO=Nothing
- Exit Function
- End If
- FSO.CopyFile TempSource,TempEnd
- Response.Write "已经成功复制文件 <b>"&TempSource&"</b> 到 <b>"&TempEnd&"</b><br />"
- Set FSO = Nothing
- End Function
- '-------------------删除文件夹--------
- strFolder="www.yuzhiguo.com"'需要删除的文件夹名称
- Call DeleteFolder(strFolder)
- Function DeleteFolder(strFolder)
- '首选判断要建立的文件夹是否已经存在
- Dim strTestFolder, objFSO
- strTestFolder = Server.Mappath(strFolder)
- Set objFSO = CreateObject("Scripting.FileSystemObject")
- ' 检查文件夹是否存在
- If objFSO.FolderExists(strTestFolder) Then
- objFSO.DeleteFolder(strTestFolder)
- response.write "<font color=red>删除成功!</font><br />"
- Else
- response.write "<font color=red>该文件夹不存在!</font>"
- End If
- Set objFSO = Nothing
- End Function
- %>
-
• JS显示当前年月日时间分秒代码(时间不断变动)
• ASP过滤所有超链接代码
• 打开网页自动弹出QQ对话框代码
• ASP按字段中首字母输出所有数据代码
• 支持中文转换的Asp UrlDecode函数
• Asp超精准判断客户端操作系统类型代码
• 忽略JS错误代码,网页屏蔽js错误代码
• ASP经常用到的代码,比较全,不可不看!
• ASP输出26个英文字母的方法代码
• asp执行出错,直接忽略错误代码