ASP複製方法用於將一個指定的文件或文件夾從一個位置複製到另一位置。可以指定overwrite屬性,以防止或允許在複製操作期間覆蓋文件。
用法:
對於文件對象:
FileObject.Copy(destination, overwrite)
對於文件夾對象:
FolderObject.Copy(destination, overwrite)
參數:該方法具有上麵提到的和下麵討論的兩個參數:
- destination:它指定將文件或文件夾複製到的目標路徑。這確實允許使用通配符。這是一個必需的參數。
- 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("<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
%>
輸出:
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("<br>" & "Folder successfully accessed")
set f=nothing
set fs=nothing
%>
輸出:
Folder is Copied! Folder successfully accessed
相關用法
- ASP Flush用法及代碼示例
- ASP End用法及代碼示例
- ASP BinaryRead用法及代碼示例
- ASP BinaryWrite用法及代碼示例
- ASP Clear用法及代碼示例
- ASP AppendToLog用法及代碼示例
- ASP AddHeader用法及代碼示例
- ASP Contents.Remove用法及代碼示例
- ASP Server.MapPath用法及代碼示例
- ASP Server.Execute用法及代碼示例
- ASP Server.Transfer()用法及代碼示例
- ASP Server.HTMLEncode()用法及代碼示例
- ASP CreateFolder()用法及代碼示例
- ASP BuildPath用法及代碼示例
- ASP GetParentFolderName用法及代碼示例
注:本文由純淨天空篩選整理自ManasChhabra2大神的英文原創作品 ASP Copy() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。