VBS教程:方法-Copy 方法


Copy 方法

将指定的文件或文件夹从某位置复制到另一位置。

object.Copy destination[, overwrite]

参数

object

必选项。应为 FileFolder 对象的名称。

destination

必选项。复制文件或文件夹的目标位置。不允许使用通配符。

overwrite

可选项。Boolean 值。如果覆盖现有文件或文件夹,则 Boolean 值为 True(默认);否则为 False

说明

对 File 或 Folder 应用 Copy 方法的结果与使用 FileSystemObject.CopyFile 或 FileSystemObject.CopyFolder 执行的操作完全相同。在 FileSystemObject.CopyFile 或 FileSystemObject.CopyFolder 中,使用 object 引用文件或文件夹,并将文件或文件夹作为参数传递给 FileSystemObject.CopyFile 或 FileSystemObject.CopyFolder。然而,应该注意的是 FileSystemObject.CopyFile 或 FileSystemObject.CopyFolder 方法可以复制多个文件或文件夹。

下列示例显示了 Copy 方法的使用:

Dim fso, MyFileSet fso = CreateObject("Scripting.FileSystemObject")Set MyFile = fso.CreateTextFile("c:\testfile.txt", True)MyFile.WriteLine("这是一个测试")MyFile.CloseSet MyFile = fso.GetFile("c:\testfile.txt")MyFile.Copy ("c:\windows\desktop\test2.txt")

« 
» 
快速导航

Copyright © 2016 phpStudy | 豫ICP备2021030365号-3