Vbscript基于起始字母复制文件
我试图让这个脚本复制所有以“XX”开头的文件。目前它只复制一个文件Vbscript基于起始字母复制文件,vbscript,copy,letters,Vbscript,Copy,Letters,我试图让这个脚本复制所有以“XX”开头的文件。目前它只复制一个文件 Dim objFSO, colFiles, objFile, strDestFolder, objNewestFile Set objFSO = CreateObject("Scripting.FileSystemObject") Set colFiles = objFSO.GetFolder("C:\source") strDestFolder = "C:\destination\" For Each objFile In
Dim objFSO, colFiles, objFile, strDestFolder, objNewestFile
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set colFiles = objFSO.GetFolder("C:\source")
strDestFolder = "C:\destination\"
For Each objFile In colFiles.Files
If Left(objFile.Name, 2) = "XX" Then
If objNewestFile = "" Then
Set objNewestFile = objFile
Else
If objNewestFile.DateLastModified < objFile.DateLastModified Then
Set objNewestFile = objFile
End If
End If
End If
Next
If Not objNewestFile Is Nothing Then
objFSO.CopyFile objNewestFile.Path,strDestFolder,True
End If
WScript.Echo "Copied."
Dim objFSO、colFiles、objFile、strDestFolder、objNewestFile
设置objFSO=CreateObject(“Scripting.FileSystemObject”)
Set colFiles=objFSO.GetFolder(“C:\source”)
strDestFolder=“C:\destination\”
对于colFiles.Files中的每个objFile
如果左(objFile.Name,2)=“XX”,则
如果objNewestFile=“”,则
设置objNewestFile=objFile
其他的
如果objNewestFile.DateLastModified
您可以在FSO.CopyFile
方法的[source]参数中使用通配符*
和?
因此,代码可能如下所示:
Dim objFSO
设置objFSO=CreateObject(“Scripting.FileSystemObject”)
objFSO.CopyFile“C:\source\XX**”,“C:\destination\”,True
Echo“已复制”
您正在循环之外执行CopyFile
操作,因此它只能复制最后一个objnewest文件
您的代码就像一个符咒。谢谢你们两位抽出时间。