Vbscript 根据开头字母复制文件

Vbscript copy files based on beginning 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 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."    

您可以在 FSO .CopyFile 方法的 [source] 参数中使用通配符 *?

因此代码可能如下所示:

Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.CopyFile "C:\source\XX*.*", "C:\destination\", True
WScript.Echo "Copied."