日期:2014-05-17  浏览次数:21006 次

请问怎么用ASP实现文件拷贝并改名?
需实现的功能如下:  
将服务器上D:\work\aaa.wav   拷贝到D:\new\目录下并改名为bbb.wav

------解决方案--------------------
VBScript 的instrrev函数
------解决方案--------------------
fso
而且要有权限
------解决方案--------------------
fso

set f=server.createobject( "scripting.filesystemobjec ")
f.CopyFile source, destination[, overwrite]

划者是adodb.stream也可以实现
另外如果服务器支持wsshell的话可以用命令,但管理不好会存在安全问题
------解决方案--------------------
fso对象没有对文件改名的方法,要想实现改名的过程,就是先把源文件复制,把复制的文件改名,最后把源文件删除
------解决方案--------------------
TempSource,TempEnd必须用绝对路径
rootPath=Request.ServerVariables( "APPL_PHYSICAL_PATH ") ‘获取当前程序绝对路径
Function CopyFiles(TempSource,TempEnd)
Dim FSO
Set FSO = Server.CreateObject( "Scripting.FileSystemObject ")
IF FSO.FileExists(TempEnd) then
Response.Write "目标备份文件 <b> " & TempEnd & " </b> 已存在,请先删除! "
Set FSO=Nothing
Exit Function
End IF
IF FSO.FileExists(TempSource) Then
Else
Response.Write "要复制的源数据库文件 <b> "&TempSource& " </b> 不存在! "
Set FSO=Nothing
Exit Function
End If
FSO.CopyFile TempSource,TempEnd
Response.Write "已经成功复制文件 <b> "&TempSource& " </b> 到 <b> "&TempEnd& " </b> "
Set FSO = Nothing
End Function
------解决方案--------------------
<%
if request( "post ") <> " " then
fullfilename=request( "name ")
filename=request( "editname ")
fillpath=left(fullfilename,instrrev(fullfilename, "\ "))
filelast=mid(fullfilename,instrrev(fullfilename, ". "))
set fso=CreateObject( "scripting.filesystemobject ")
if fso.fileexists(fillpath&filename&filelast) then
response.Write( " <script language=javascript> alert( '文件已经存在 ');location= 'javascript:history.go(-1) ' </script> ")
response.end
else
fso.copyFile fullfilename,fillpath&filename&filelast
response.Write( " <script language=javascript> alert( '修改成功 ') </script> ")
fso.deletefile(fullfilename)
end if
end if
%>
------解决方案--------------------
<%set fso=server.createobject( "scripting.filesystemobject ")
File_path= "D:\New " '判断目录
if fso.folderexists( " "&File_path& " ")=false then '不存在的时候
set pgsky=fso.createfolder( " "&File_path& " ") '创建目录
end if

fso.CopyFile "D:\work\aaa.wav ", "D:\New\bbb.wav "

response.write "操作成功 "

response.end%>