2017-05-02 9 views
2

"XX"로 시작하는 모든 파일을 복사하려면이 스크립트를 가져 오려고합니다. 현재는 하나의 파일 만 복사합니다.시작 문자를 기준으로 VBScript 복사 파일

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."  
+0

당신은 루프 밖에서'CopyFile'을하고, 그래서 마지막'objNewestFile' –

답변

2

당신은 FSO .CopyFile 방법의 [소스] 인수에 와일드 카드 *?를 사용할 수 있습니다.

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

귀하의 코드가 마법처럼 작동 복사 할 수 있습니다 : 같은

그래서 코드가 보일 수 있습니다. 둘 다 시간 내 주셔서 감사합니다. – user3374569