【问题标题】:Vbscript copy files based on beginning lettersvbscript 根据开头字母复制文件
【发布时间】:2017-09-30 01:38:11
【问题描述】:

我试图让这个脚本复制所有以“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."    

【问题讨论】:

  • 你在循环外做CopyFile,所以它只能复制最后一个objNewestFile

标签: vbscript copy letters


【解决方案1】:

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

所以代码可能看起来像:

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

【讨论】:

  • 你的代码就像一个魅力。谢谢你们的时间。
猜你喜欢
  • 1970-01-01
  • 2014-08-30
  • 1970-01-01
  • 2016-08-15
  • 2021-12-08
  • 2013-11-24
  • 2018-12-29
  • 2011-08-06
  • 1970-01-01
相关资源
最近更新 更多