在VBS中复制文件时出错
|
Sub Copy_Files_Dates()
\'This example copy all files between certain dates from FromPath to ToPath.
\'You can also use this to copy the files from the last ? days
\'If Fdate >= Date - 30 Then
\'Note: If the files in ToPath already exist it will overwrite
\'existing files in this folder
Dim FSO As Object
Dim FromPath As String
Dim ToPath As String
Dim Fdate As Date
Dim FileInFromFolder As Object
FromPath = \"C:\\Users\\Ron\\Data\" \'<< Change
ToPath = \"C:\\Users\\Ron\\Test\" \'<< Change
If Right(FromPath, 1) <> \"\\\" Then
FromPath = FromPath & \"\\\"
End If
If Right(ToPath, 1) <> \"\\\" Then
ToPath = ToPath & \"\\\"
End If
Set FSO = CreateObject(\"scripting.filesystemobject\")
If FSO.FolderExists(FromPath) = False Then
MsgBox FromPath & \" doesn\'t exist\"
Exit Sub
End If
If FSO.FolderExists(ToPath) = False Then
MsgBox ToPath & \" doesn\'t exist\"
Exit Sub
End If
For Each FileInFromFolder In FSO.getfolder(FromPath).Files
Fdate = Int(FileInFromFolder.DateLastModified)
\'Copy files from 1-Oct-2006 to 1-Nov-2006
If Fdate >= DateSerial(2006, 10, 1) And Fdate <= DateSerial(2006, 11, 1) Then
FileInFromFolder.Copy ToPath
End If
Next FileInFromFolder
MsgBox \"You can find the files from \" & FromPath & \" in \" & ToPath
End Sub
我遇到错误
line 1
char 9
error expected end of statement
code 800A0401
没有找到相关结果
已邀请:
1 个回复
冲汉
更改为
:
和
只是
。
这看起来像是您试图作为VBS工作的VB6代码段。 VB6和VBS之间有一些细微的区别,您需要注意。 我修复了这些问题,尽管我实际上并未测试它是否正确复制了文件,但它似乎可以正常运行。