【发布时间】:2011-06-27 12:43:25
【问题描述】:
这是我的第一个问题,希望您能提供帮助。
这是一个脚本,仅当文件是新文件时,才将每个子文件夹中的文件移动到另一个文件夹中
例如
C:\Test\Sub1
C:\Test\Sub1\Sub
C:\Test\Sub2\Sub
D:\Test\Sub1
D:\Test\Sub1\Sub
D:\Test\Sub2\Sub
我现在要做的是,当它发现C:\Test\Sub2\Sub中有一个扩展名为Pdf,zip,xls的新文件时,它将直接移动到D:\Test\Sub2\Sub。
然后它将循环整个test文件夹并按照上述规则移动文件。 我一直在寻找一些例子,但那些不适合。
提前谢谢你。
编辑
Option Explicit
const DestFolder = "B:\Testing\"
MoveFiles
Sub MoveFiles
' folder to look in
Dim strFolderPath : strFolderPath = "D:\Temp\Testing\"
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim RegEx : Set RegEx = New RegExp
' specify the extension you want to search for; seperate with a |
' currently searching for .txt and .mdb files
RegEx.Pattern = "\.(pdf|zip|xls|txt)$"
RegEx.IgnoreCase = True
RecurseFolder objFSO, strFolderPath, RegEx
End Sub
Sub RecurseFolder(objFSO, strFolderPath, RegEx)
Dim objFolder : Set objFolder = objFSO.GetFolder(strFolderPath)
Dim objFile, strFileName,dest
For Each objFile In objFolder.Files
strFileName = objFile.Path
If RegEx.Test(strFileName) Then
'Checking whether file exist in destination
if not objFSO.FileExists(destfolder.strFileName) then
objFile.Move destfolder
else
msgbox "File is already existed"
End If
End If
Next
Dim objSubFolder
For Each objSubFolder In objFolder.SubFolders
RecurseFolder objFSO, objSubFolder.Path, RegEx
Next
End Sub
我可以循环浏览子文件夹,但不能根据源文件夹移动到文件夹。例如,
FileA 来自D:\Temp\A。它将被移至B:\Temp\A。但现在它只移到了B:\Temp。此外,由于我只能使用记事本编写 vbs,我无法弄清楚检查现有文件是否有任何错误。对吗?
请帮帮我。我会非常感谢你的好意。
【问题讨论】:
-
请向我们展示您自己的尝试。
-
我已经展示过了。请看一下