Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

copy file

Status
Not open for further replies.

famtek

Instructor
Mar 27, 2007
67
US
Within the same web site, I want to copy a file from one folder to another. Would appreciate suggestions. thanks
 
This looks perfect BUT can you please advise how to structure my HTML code to use it. thanks.
 
Just confirmed with my hosting soervice that my folder has FULL permissions. Trying to get the following to copy a file and then delete it. The file is found, but none of the required actions are implmented. Help. thanks.

<html>
<head>
<title>New Page 1</title>
</head>
<body>
<%
strFileSource = Server.MapPath("\sunshine\deletethisfile.txt")
strFileDestination = Server.MapPath("\sunshine\FILECOPIED.txt")

strError="File is OK"

set fso = Server.CreateObject("Scripting.FileSystemObject")
if Not fso.FileExists(strFileSource) then
strError = "Error - Source file does not exist = " & strFileSource
end if

if strError = "" then
Set f2 = fso.GetFile(strFileSource)
f2.Copy(strFileDestination)
f2.DeleteFile(strFileSource)
Set f2 = nothing
end if

Set fso = nothing
%>
file = <%=strFileSource%><br/>
Result = <%=strError%>
f2 = <%=f2%>
</body>
</html>
 
ok - you cant use getfile to delete the file, you have to use the object fso

eg.
Code:
strFileSource = Server.MapPath("deletethisfile.txt")
strFileDestination = Server.MapPath("FILECOPIED.txt")

strError="File is OK"

set fso = Server.CreateObject("Scripting.FileSystemObject")
if Not fso.FileExists(strFileSource) then
  strError = "Error - Source file does not exist = " & strFileSource
else
  Set f2 = fso.GetFile(strFileSource)
  f2.Copy (strFileDestination)
   fso.DeleteFile (strFileSource)
  Set f2 = nothing
end if

Set fso = nothing

also found this really good page about files
 
Many thanks, but still doesn't work. When implemented a copy or delete is there an error message that can help me better understand what's wrong. Thanks for the link but most examples use files from the local drive when I am trying to act upon files from my web server. It makes me wonder if these FSO methods work on web servers via an ASP page.
 
...by the way tried the file on my fasthosts account and worked fine
 
heres the full code i used - jus copy and paste

Code:
<html>
<head>
<title>New Page 1</title>
</head>
<body>
<%
strFileSource = Server.MapPath("deletethisfile.txt")
strFileDestination = Server.MapPath("FILECOPIED.txt")

strError="File is OK"

set fso = Server.CreateObject("Scripting.FileSystemObject")
if Not fso.FileExists(strFileSource) then
  strError = "Error - Source file does not exist = " & strFileSource
else
  Set f2 = fso.GetFile(strFileSource)
  f2.Copy (strFileDestination)
   fso.DeleteFile (strFileSource)
  Set f2 = nothing
end if

Set fso = nothing
%>
file = <%=strFileSource%><br/>
Result = <%=strError%>
f2 = <%'=f2%>
</body>
</html>
 
Thanks. Got the filecopy to work. I'm now down to the delete file method. I get a generic IE7 error page that you have a problem with your server. Is there a way to take your above code and trap any error.

thanks for your help.
 
hi - have you got friendly HTTP errors turned off

[tools > internet options > untick friendly http errors]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top