Skip to content
Related Articles

Related Articles

Improve Article
ASP Copy() Method
  • Last Updated : 24 Mar, 2021

The ASP Copy Method is used to copying one specified file or folder from one place to another place. The overwrite attribute can be specified to prevent or allow the overwriting of files during the copy operation.

Syntax:

  • For File Object: 

    FileObject.Copy(destination, overwrite)
  • For Folder Object:

    FolderObject.Copy(destination, overwrite)

Parameters: This method has two parameters as mentioned above and discussed below:



  • destination: It specifies the destination path where the file or folder would be copied to. This does allow wildcard characters. This is a required parameter.
  • overwrite: It contains a boolean value that indicates whether an existing file or folder can be overwritten or not. The default value is true This is an optional parameter.

The below examples demonstrate the ASP Copy Method.

Example 1: The below code demonstrates the ASP File.Copy Method.

ASP




<%
dim fs,f,ts
set fs=Server.CreateObject("Scripting.FileSystemObject")
  
'Getting the file to be copied
set f=fs.GetFile("d:\GFG.txt")
  
'Reading the contents of the file
set ts=f.OpenAsTextStream(1)
Response.Write("Original File Content: " & ts.ReadAll)
ts.Close
  
'Copying the file to the given path
'f.Copy("d:\geeks.txt", false)
  
Response.write("<br>" & "File is Copied!" & "<br>")
  
'Getting the copied file
set f=fs.GetFile("d:\geeks.txt")
  
'Reading the contents of the copied file
set ts=f.OpenAsTextStream(1)
Response.Write("Copied File Content: " & ts.ReadAll)
ts.Close
  
set f=nothing
set fs=nothing
%>

Output:

Original File Content: This is a GeeksforGeeks example
File is Copied!
Copied File Content: This is a GeeksforGeeks example 

Example 2: The below code demonstrates the ASP Folder.Copy Method.

ASP




<%
dim fs,f,ts
set fs=Server.CreateObject("Scripting.FileSystemObject")
  
'Getting the folder to be copied
set f=fs.GetFolder("d:\GFG")
  
'Copying the folder to the given path
f.Copy("d:\newfolder\GFG")
  
Response.write("Folder is Copied!")
  
'Getting the copied folder
set f=fs.GetFolder("d:\newfolder\GFG")
  
Response.write("<br>" & "Folder successfully accessed")
  
set f=nothing
set fs=nothing
%>

Output:

Folder is Copied!
Folder successfully accessed



My Personal Notes arrow_drop_up
Recommended Articles
Page :