【发布时间】:2018-09-11 01:33:33
【问题描述】:
尝试将多个文件从一个文件夹移动到另一个文件夹,但在文件复制行出现错误。我尝试删除直接传递给路径的字符串,如下所示,但仍然抛出错误 - “找不到文件”
Sub MoveFiles_3()
Dim fso As Object
Dim d As String, ext, x
Dim srcPath As String, destPath As String, srcFile As String
srcPath = "C:\Users\rohit.keskar\Desktop\Test Macro"
destPath = "C:\Users\rohit.keskar\Desktop\Archive Test"
Set fso = CreateObject("Scripting.FileSystemObject")
ext = Array("*.xlsx")
MsgBox Dir(srcPath)
For Each x In ext
d = Dir(srcPath & x)
Do While d <> ""
srcFile = srcPath & d
fso.CopyFile "C:\Users\rohit.keskar\Desktop\Test Macro" & d, "C:\Users\rohit.keskar\Desktop\Archive Test" & d
Kill "C:\Users\rohit.keskar\Desktop\Test Macro" & d
d = Dir
Loop
Next
MsgBox "done"
End Sub
【问题讨论】:
-
每条路径的末尾都需要一个反斜杠。
-
谢谢,我一贴在这里就意识到了。