ASP Copy() 方法
ASP复制方法用于将一个指定的文件或文件夹从一个地方复制到另一个地方。可以指定覆盖属性以防止或允许在复制操作期间覆盖文件。
句法:
对于文件对象:
FileObject.Copy(destination, overwrite)
对于文件夹对象:
FolderObject.Copy(destination, overwrite)
参数:此方法有两个参数,如上所述,下面讨论:
- 目的地:它指定文件或文件夹将被复制到的目标路径。这确实允许字符。这是一个必需的参数。
- overwrite:它包含一个布尔值,指示是否可以覆盖现有文件或文件夹。默认值为 true 这是一个可选参数。
下面的例子演示了ASP 复制方法。
示例 1:下面的代码演示了 ASP File.Copy 方法。
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("
" & "File is Copied!" & "
")
'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
%>
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("
" & "Folder successfully accessed")
set f=nothing
set fs=nothing
%>
输出:
Original File Content: This is a GeeksforGeeks example
File is Copied!
Copied File Content: This is a GeeksforGeeks example
示例 2:下面的代码演示了 ASP Folder.Copy 方法。
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("
" & "Folder successfully accessed")
set f=nothing
set fs=nothing
%>
输出:
Folder is Copied!
Folder successfully accessed