0

我有个问题。我需要在我的循环的每个循环中在 vbscript 中抛出一些同步命令(一个运行方法,删除一个和 moveFile 一个)。我不知道我是怎么做到的。

我的代码是:

Public Function UnificarCRIs(ByVal path, ByVal FICRIEC, ByVal sessio, ByVal CIBAA)
    Dim objFile, objCurrentFolder, filesys, origenFitxers
    Dim FileName, WshShell

    On error resume next

    Set filesys = CreateObject("Scripting.FileSystemObject")
    Set WshShell = WScript.CreateObject("WScript.Shell")
    Set objCurrentFolder = filesys.getFolder(path)

    For Each objFile In objCurrentFolder.Files
        FileName = objFile
        If (right(FileName, 4) = ".cri") Then
            If filesys.FileExists(path & FICRIEC & sessio) Then
                 'WshShell.Run ("copy " & path & FICRIEC & sessio & "+" & FileName & " " & path & FICRIEC & sessio & "_tmp")
                 WshShell.run ("cmd /K " & "copy /Y " & path & FICRIEC & sessio & "+" & FileName & " " & path & FICRIEC & sessio & "_tmp",8,TRUE)
                 Set WshShell = Nothing
                 filesys.DeleteFile path & FICRIEC & sessio
                'filesys.MoveFile path & FICRIEC & sessio & "_tmp", path & FICRIEC & sessio
            Else
                WshShell.run "cmd /K " & "copy /Y " & FileName & " " & path & FICRIEC & sessio,8,TRUE
                Set WshShell = Nothing
            End If     
        End If 
    Next

End Function
4

1 回答 1

0

完整阅读.Run 的文档 并反思参数。bWaitOnReturn

道歉:

抱歉,我没有仔细阅读您的代码。.Run 应该等待。但是我看到您在中使用了全局On Error Resume Next和参数列表()

WshShell.run ("cmd /K " & "copy /Y " & path & FICRIEC & sessio & "+" & FileName & " " & path & FICRIEC & sessio & "_tmp",8,TRUE)

当你消除这些错误时会发生什么?你确定你WshShell在第二次循环中可以使用吗?

于 2013-02-14T10:31:04.243 回答