MoveFile 方法将一个或多个文件从一个位置移动到另一个位置。
语法
object.MoveFile ( source, destination )
参数:
FileSystemObject 的名称。注释
仅允许在源路径的末尾使用通配符。如果传递了任何不正确的路径,则会弹出错误,指出源文件或目标目录不存在。
以下示例说明了 MoveFile 方法的用法:
示例 1:
Function MoveSingleFile(source, destination)
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
fso.MoveFile source, destination
End Function
' Usage
MoveSingleFile "C:\Path\To\Source\File.txt", "C:\Path\To\Destination\File.txt"
示例 2:
注:
如果在源路径中使用通配符,则目标必须是现有目录。否则,您将收到错误消息,指出目录不存在。
Function MoveMultipleFiles(source, destination)
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
fso.MoveFile source, destination
End Function
' Usage
MoveMultipleFiles "C:\Path\To\Source\*.txt", "C:\Path\To\Destination\" 'Here Destination Directory must exists