Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vbscript基于起始字母复制文件_Vbscript_Copy_Letters - Fatal编程技术网

Vbscript基于起始字母复制文件

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

我试图让这个脚本复制所有以“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."    
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文件
您的代码就像一个符咒。谢谢你们两位抽出时间。