VBS。将具有特定扩展名的文件复制到另一个文件夹

VBS. Copy files with certain extension to another folder

我有这个代码:

For Each sFile In oFSO.GetFolder(sOriginFolder).Files
If Not oFSO.FileExists(sDestinationFolder & "\" &  oFSO.GetFileName(sFile)) Then
oFSO.GetFile(sFile).Copy sDestinationFolder & "\" & oFSO.GetFileName(sFile),True
End If
Next

而且我想加一个条件,就是当文件是.txt文件的时候,我只想复制它。谢谢。

这样试试:

For Each sFile In oFSO.GetFolder(sOriginFolder).Files
If LCase(oFSO.GetExtensionName(sFile)) = "txt" Then
    If Not oFSO.FileExists(sDestinationFolder & "\" &  oFSO.GetFileName(sFile)) Then
        oFSO.GetFile(sFile).Copy sDestinationFolder & "\" & oFSO.GetFileName(sFile),True
    End If  
End If
Next