當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


ASP Move()用法及代碼示例

ASP移動方法用於將指定的文件或文件夾移動到給定的目標。

用法:

  • 對於文件對象:

    FileObject.Move(destination)
  • 對於文件夾對象:

    FolderObject.Move(destination)

參數:該方法具有上麵提到的和下麵討論的單個參數:



  • destination:它指定文件或文件夾將被移動到的目的地。它不允許使用通配符。這是一個必需的參數。

下麵的示例演示ASP移動方法。

範例1:下麵的代碼演示了ASP File.Move方法。

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
  
'Moving the file to the given path
f.Move("d:\newfolder\GFG.txt")
  
Response.write("<br>" & "File is Moved!" & "<br>")
  
'Getting the moved file
set f=fs.GetFile("d:\newfolder\GFG.txt")
  
'Reading the contents of the moved file
set ts=f.OpenAsTextStream(1)
Response.Write("Moved File Content:" & ts.ReadAll)
ts.Close
  
set f=nothing
set fs=nothing
%>

輸出:

Original File Content:This is an example file
File is Moved!
Moved File Content:This is an example file

範例2:下麵的代碼演示了ASP Folder.Move方法。

ASP


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

輸出:

Folder is Moved!
Folder successfully accessed

相關用法


注:本文由純淨天空篩選整理自ManasChhabra2大神的英文原創作品 ASP Move() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。