首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> 網頁程式設計 >> ASP 程式設計 >> ASP 入門教學

ASP 入門教學:檔案系統物件模型 - 檔案操作

     編輯:ASP 入門教學

FileSystemObject 檔案操作方法

方法語法說明
CopyFilefso.CopyFile source, destination[, overwrite]複製檔案,支援萬用字元,預設覆蓋
MoveFilefso.MoveFile source, destination移動檔案,目的地不可為現有檔案或目錄
DeleteFilefso.DeleteFile filespec[, force]刪除檔案,force=True 可刪除唯讀檔案

File 物件方法(取得 File 物件後操作)

方法語法說明
Copyfile.Copy destination[, overwrite]複製檔案
Movefile.Move destination移動檔案
Deletefile.Delete[, force]刪除檔案

實作範例一:FSO 方法建立/複製/移動/刪除

Set fso = Server.CreateObject("Scripting.FileSystemObject")
Set txtFile = fso.CreateTextFile(Server.MapPath("temp1.txt"))
txtFile.WriteLine("Hello!")
txtFile.Close

fso.CopyFile Server.MapPath("temp1.txt"), Server.MapPath("temp2.txt")
fso.MoveFile Server.MapPath("temp2.txt"), Server.MapPath("temp3.txt")
fso.DeleteFile Server.MapPath("temp1.txt")
fso.DeleteFile Server.MapPath("temp3.txt")

實作範例二:File 物件方法操作

Set afile = fso.GetFile(Server.MapPath("temp1.txt"))
afile.Copy Server.MapPath("temp2.txt"), True
afile.Move Server.MapPath("temp3.txt")
afile.Delete

注意:GetFile 取得的是當時的檔案物件,若後續 Move 導致原檔名被取代,後續 Delete 作用於新位置檔案。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved