Open In App

ASP Copy() Method

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:



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

The below examples demonstrate the ASP Copy Method.

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




<%
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.




<%
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

Article Tags :