asp中movefile server.mappath(), server.mappath()d的报错

来源:百度知道 编辑:UC知道 时间:2024/05/15 05:23:59
如果文件已经存在,怎么办?
而且要覆盖已有的文件。
谢谢啦!

MoveFile source, destination.这个方法对文件进行移动操作,同样你可以使用通配符来移动多个文件,不过如果目的文件已经存在,则会报错而不允许覆盖

所以你需要用CopyFile,给你个例子:
<%
function copyfile(a,b)
set fso=server.createobject("scripting.filesystemobject")
fso.copyfile server.mappath(a),server.mappath(b), true
response.write "<div align=center>Ok,You Have Succeed!!"
set fso=nothing
end function
copyfile "2.asp","sdffsd.asp"

%>

先检测一下目标文件是否存在;
要覆盖的话,可以直接在后面加个参数:
movefile server.mappath(...),server.mappath(..),true