求助:根据获取地址浏览器URL,自动创建不存在的目录文件夹。

小獭 2019-01-03 08:46:38
浏览器地址:
http://localhost/Html/a/b/4041.asp

通过获取浏览器地址,
requestURL=Request.ServerVariables("QUERY_STRING")

response.Write(requestURL)

得到:
/Html/a/b/4041.asp

我想实现:

如果html、a、b文件夹不存在,依次就创建该路径的三个文件夹,

即:网站根目录下,创建一个文件夹叫html,“html”文件夹里又创建“a”文件夹,“a”文件夹里又创建了b文件夹。

如果其中文件夹已经存在,则跳过,不创建。

请问ASP程序要怎么实现?

也就是说,我根据每次浏览器的不同地址,创建该浏览器地址所需要的文件夹。
如果当浏览器地址是http://localhost/a/b/4041.asp时,网站根目录下,“a”和“b”两个文件夹则帮我创建这两个文件夹,即创建a文件夹,并在a文件夹里又创建了b文件夹。

依此类推。

谢谢大神们。
...全文
393 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
csdn_aspnet 2019-01-18
  • 打赏
  • 举报
回复

FSO中有个方法是CreateFolder,但是这个方法只能在其上一级文件夹存在的情况下创建新的文件夹,所以我就写了一个自动创建多级文件夹的函数,在生成静态页面等方面使用非常方便.

函数:
  
' --------------------------------
' 自动创建指定的多级文件夹
' strPath为绝对路径
' 引用请保留版权
' by im286_Anjer
' 2005-4-3
Function AutoCreateFolder(strPath) ' As Boolean
        On Error Resume Next

        Dim astrPath, ulngPath, i, strTmpPath
        Dim objFSO

        If InStr(strPath, "\") <=0 Or InStr(strPath, ":") <= 0 Then
                AutoCreateFolder = False
                Exit Function
        End If
        Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
        If objFSO.FolderExists(strPath) Then
                AutoCreateFolder = True
                Exit Function
        End If
        astrPath = Split(strPath, "\")
        ulngPath = UBound(astrPath)
        strTmpPath = ""
        For i = 0 To ulngPath
                strTmpPath = strTmpPath & astrPath(i) & "\"
                If Not objFSO.FolderExists(strTmpPath) Then
                        ' 创建
                        objFSO.CreateFolder(strTmpPath)
                End If
        Next
        Set objFSO = Nothing
        If Err = 0 Then
                AutoCreateFolder = True
        Else
                AutoCreateFolder = False
        End If
End Function 
 


调用方法:

MyPath = "C:\a\b\c\"
If AutoCreateFolder(MyPath) Then
        Response.Write "创建文件夹成功"
Else
        Response.Write "创建文件夹失败"
End If 
  • 打赏
  • 举报
回复
SavePath = "/html/a/b/c/"
CreateFolder SavePath '文件夹不存则会创建'

Function CreateFolder(byval s)
Dim Fso,upPath,path
Set Fso = Server.CreateObject("Scripting.FileSystemObject")
If Fso.FolderExists(Server.MapPath(s)) Then Exit Function
upPath = Replace(Server.MapPath(s),Server.MapPath("/"),"")
upPath = Replace(upPath,"\","/")
If left(upPath,1)<>"/" Then
upPath = "/"&upPath
End If
If right(upPath,1)<>"/" Then
upPath = upPath&"/"
End If
Folder_arr = split(upPath,"/")
path = ""
For i = 1 To Ubound(Folder_arr)-1
path = path&"/"&Folder_arr(i)
Set objFolder = Server.CreateObject("Scripting.FileSystemObject")
If Not objFolder.FolderExists(Server.MapPath(path)) Then
objFolder.CreateFolder(Server.MapPath(path))
End If
Set objFolder = Nothing
Next
Set Fso = Nothing
End Function

28,390

社区成员

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

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