ASP创建文件夹、文件以及、文件的重命名

Time:2020/3/9  keywords:ASP创建文件夹,ASP创建文件,ASP操作文件的重命名

'建立文件夹

set fso = Server.CreateObject("scripting.filesystemobject") 

If fso.folderexists(Server.MapPath("\New Folder")) Then

Response.write "文件夹已经创建<br/>"

Else 

fso.CreateFolder(Server.MapPath("\New Folder"))

Response.write "创建成功<br/>"

End If 


'移动文件夹(重命名文件夹)

set fso = Server.CreateObject("scripting.filesystemobject")

If fso.folderexists(Server.MapPath("\Move Folder")) Then

fso.movefolder Server.MapPath("\Move Folder"), Server.MapPath("\Moved Folder")

Response.write "文件夹移动成功<br/>"

Else 

Response.write "文件夹不存在,不能执行移动<br/>"

End If 


'删除文件夹

set fso = Server.CreateObject("scripting.filesystemobject")

If fso.folderexists(Server.MapPath("\Delete Folder")) Then

fso.deletefolder(Server.MapPath("\Delete Folder"))

Response.write "文件夹删除成功<br/>"

Else 

Response.write "文件夹不存在,不能执行删除<br/>"

End If 


'创建txt文件

set fso = Server.CreateObject("scripting.filesystemobject")

If fso.fileexists(Server.MapPath("\New File.asp")) Then

Response.write "文件已经存在,无法创建<br/>"

Else 

fso.CreateTextFile(Server.MapPath("\New File.asp"))

Response.write "创建文件成功<br/>"

End If 


'移动文件(重命名文件)

set fso = Server.CreateObject("scripting.filesystemobject")

If fso.fileexists(Server.MapPath("\Move File.asp")) Then 

fso.movefile Server.MapPath("\Move File.asp"), Server.MapPath("\moved File.asp")

Response.write "文件移动(重命名)成功"

Else 

Response.write "文件不存在,无法移动<br/>"

End If 


'删除文件

set fso = Server.CreateObject("scripting.filesystemobject")

If fso.fileexists(Server.MapPath("\Delete File.asp")) Then 

fso.deletefile(Server.MapPath("\Delete File.asp"))

Response.write "删除文件成功"

Else 

Response.write "文件不存在,无法删除文件<br/>"

End If 


'复制文件

set fso = Server.CreateObject("scripting.filesystemobject")

If fso.fileexists(Server.MapPath("\copy File.asp")) Then 

fso.copyfile Server.MapPath("\copy File.asp"), Server.MapPath("\复件copy File.asp")

Response.write "文件复制成功"

Else 

Response.write "文件不存在,无法复制<br/>"

End If 

set fso = nothing