Dim objFSO
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
path = Server.MapPath("\upload\user")
If objFSO.FolderExists(path) Then
Response.Write path&"文件夹已经存在!"
Else
objFSO.CreateFolder(path)
Response.Write "新建文件夹的位置为"&path
End If
Set objFSO = Nothing
花衣燕子这下出名了
下面是表单代码:<form id="form1" name="form1" method="post" action="folder.asp">
请指定<span class="STYLE3">文件位置和文件名: <input type="text" name="createflie">
<input type="submit" name="Submit" value="确定" />
</form>
提交到folder.asp
<%
folder = request("createflie")
set fso = server.CreateObject("scripting.filesystemobject")
fso.createfolder(server.MapPath(".\"&folder&""))
response.Write("文件夹创建成功")
%>
经测试可以创建成功
asp 创建文件与文件夹代码参考如下:'==============================
'函 数 名:CreateFolder
'作用:创建文件夹
'参数:文件夹相对路径FolderPath
'==============================
Function CreateFolder(FolderPath)
' On Error Resume Next
Set Fso=Server.CreateObject("Scri"&"pting.File"&"Sys"&"temObject")
Set F=Fso.CreateFolder(Server.MapPath(FolderPath))
CreateFolder=F.Path
Set F=Nothing
Set Fso=Nothing
' Select Case Err
' Case 424 Response.Write("方卡错误提示:创建"&FolderPath&"文件夹时,路径未找到或者该目录没有写入权限!")
' End Select
End Function
'==============================
'函 数 名:CreateFile
'作用:创建文件
'参数:文件相对路径FilePath,文件内容FileContent
'==============================
Function CreateFile(FilePath,FileContent)
' On Error Resume Next
Dim Temps
Temps=""
TempArr=Split(FilePath,"/")
For i=0 to UBound(TempArr)-1
If Temps="" Then
Temps=TempArr(i)
Else
Temps=Temps&"/"&TempArr(i)
End If
If IsFolder(Temps)=False Then
Call CreateFolder(Temps)
End If
Next
Set objAdoStream = Server.CreateObject("A"&"dod"&"b.St"&"r"&"eam")
objAdoStream.Type = 2
objAdoStream.Charset = "UTF-8"
objAdoStream.Open
objAdoStream.WriteText = FileContent
objAdoStream.SaveToFile Server.MapPath(FilePath),2
objAdoStream.Close()
Set objAdoStream = Nothing
' Select Case Err
'Case 424 Response.Write("方卡错误提示:创建"&FilePath&"文件时,路径未找到或者该目录没有写入权限!")
' End Select
End Function
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)