Your source for ASP-related frequently asked questions and answers! : ASP FAQS : FileSystemObject

Question: How can I copy a file using ASP?

Answer: You can copy a file in ASP using the Scripting.FileSystemObject which is built into the Windows scripting engine. I have written the following CopyFile() function that you can use to copy a file. Note that the anonymous Internet account user (usually IUSR_machinename), must have read access to the directories and file that are involved in the copy). For more info on the IUSR_machinename account be sure to read this FAQ:

'Name : CopyFile
'Purpose : Copy file from source to destination
'Input: StrFileSource - path to file you want to copy
' StrFileDestination - path that file destination
'Output: StrError - Error Message
'Author : Ian Stallings
'Date : 09/27/00

function CopyFile(strFileSource, strFileDestination, strError)

if strFileSource = "" OR strFileDestination = "" then
  strError = "Error - You must supply both a source and a destination"
  exit function
end if

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

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

Set fso = nothing

end function

For more info on using the FileSystemObject check out:
-- Reading/Writing Text Files Using ASP
-- MSDN - Scripting

FAQ posted by shedao at 9/27/2000 3:14:55 PM to the FileSystemObject category. This FAQ has been viewed 65,249 times.

Copyright 2017 QuinStreet Inc. All Rights Reserved.
Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers