FSO小问题~移动文件到文件夹并覆盖原有文件!~~在线期待~~
原先在upload\doc\文件夹下有一个123.doc文件~
现在我又重新上传了一个123.doc文件~~
我要实现的是我刚刚上传的123.doc文件可以移动到doc文件夹下并且覆盖掉原有的123.doc文件~
请问高手怎么加入代码实现~~谢谢~~在线期待~~
Set fso = CreateObject( "Scripting.FileSystemObject ")
aa=Server.MapPath( ". ")& "\upload\123.doc "
bb=Server.MapPath( ". ")& "\upload\doc\ "
fso.OpenTextFile (aa)
fso.MoveFile aa,bb
------解决方案--------------------set FSO=server.CreateObject( "Scripting.FileSystemObject ")
aa=server.mappath( "/CDFILE/ "&Trim(rs( "filekkk "))& "/ ")
if FSO.FolderExists(aa) then
CreateFolder=aa
else
FSO.CreateFolder(aa)
CreateFolder=aa
end if
if Trim(rs( "filekkk ")) <> " " then
FileExt0 =split(lcase(Trim(rs( "filekkk "))), ". ") '重要修改,防止黑客 "\0 "断名伪装!!!
FileExt=FileExt0(ubound(FileExt0)) '重要修改,防止黑客 "\0 "断名伪装!!
filenamesql=replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(rs( "filetitle "), " " " ", " "), " ", " "), " < ", " "), "> ", " "), " ' ", " "), "\ ", " "), "/ ", " "), ". ", " "), ": ", " "), "* ", " "), ", ", " "), "? ", " ")& ". "&FileExt
FileName=aa& "\ "&filenamesql
SFile =server.mappath( "/upfile/ "&lcase(Trim(rs( "filekkk ")))) '源文件名
TFile =FileName
if FSO.FileExists(SFile) then
FSO.CopyFile SFile,TFile
Response.Write "成功复制文件!ID= "&rs( "fileid ")
response.flush()
i=i+1
else
Response.Write " <hr> 【【【【这个文件不存在!ID= "&rs( "fileid ")& " 】】】 "&SFile
response.flush()
end if
end if
------解决方案--------------------Set fso = CreateObject( "Scripting.FileSystemObject ")
aa=Server.MapPath( ". ")& "\upload\123.doc "
bb=Server.MapPath( ". ")& "\upload\doc\ "
fso.MoveFile aa,bb
------解决方案--------------------告诉你个窍门,使用fso的
fso.MoveFile 这样是使用fso对象,也就是顶层的
fso.OpenTextFile 返回的是个textstream对象
fso还有folders集合 folder对象 files集合 file对象 等等
你只要把对象搞清楚了就可以了,简称 搞对象 这个是asp中不可少的
------解决方案--------------------恩!--搞对象...!!
------解决方案--------------------学习
------解决方案--------------------Sub MoveAFile(Drivespec)
Dim fso
Set fso = CreateObject( "Scripting.FileSystemObject ")
fso.MoveFile Drivespec, "c:\windows\desktop\ "
End Sub
这个是手册上写的......再不明白就拉倒了,这种无聊的问题,没必要跟你讲太多,你不懂不是我的事....
下个脚本手册...fso这种超简单的东西....无语