FileSystemObject 檔案操作方法
| 方法 | 語法 | 說明 |
| CopyFile | fso.CopyFile source, destination[, overwrite] | 複製檔案,支援萬用字元,預設覆蓋 |
| MoveFile | fso.MoveFile source, destination | 移動檔案,目的地不可為現有檔案或目錄 |
| DeleteFile | fso.DeleteFile filespec[, force] | 刪除檔案,force=True 可刪除唯讀檔案 |
File 物件方法(取得 File 物件後操作)
| 方法 | 語法 | 說明 |
| Copy | file.Copy destination[, overwrite] | 複製檔案 |
| Move | file.Move destination | 移動檔案 |
| Delete | file.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 作用於新位置檔案。