1

I need to delete (remove) files (and possibly folders) via Excel VBA in Tortoise SVN environment. However I change my command, it always deletes the folder where files reside.

Call obj.Run("TortoiseProc.exe /command:remove /pathfile:""C:\someSVNpath\123.txt"" /closeonend:1 ")

Call obj.Run("TortoiseProc.exe /command:remove /pathfile:""C:\someSVNpath\Folder"" /closeonend:1 ")

I was also trying to list files in the loop and delete, but then the error appears: Subversion reported an error: Previous operation has not finished; run 'cleanup' if it was interrupted. Please execute the 'Cleanup' command.

Also, even if I manage to list the files in the loop and delete, the commit operation does not find any files for committing.

Dim obj, FSO, folder, file As Object
Dim b, c, p(1 To 2) As String

Set obj = CreateObject("WScript.Shell")
Set FSO = CreateObject("Scripting.FileSystemObject")

b = "C:\someSVNlocation\folder\"

With ThisWorkbook.Sheets("Equity")
    p(1) = "loc1"
    p(2) = "loc2"
    
    For i = 1 To 2
        If p(i) <> "" Then
            c = b & "\" & p(i) & "\"
            Set folder = FSO.GetFolder(c)
            For Each file In folder.Files
                d = c & file.Name
                Call obj.Run("TortoiseProc.exe /command:remove /path:""" & d & """ /closeonend:1 ")
                d = ""
            Next file
        End If
    Next
    
    Call obj.Run("TortoiseProc.exe /command:commit /path:""" & p(1) & """ * """ & p(2) & """ ")

End With

1 Answer 1

0

I think your main problem is that you aren't waiting for the shell to return. These operations are likely running asynchronously and running over each other. This is a sort of race condition.

I fix this by adding , 1, True to the end of the .Run command. The 1 is a intWindowStyle that "Activates and displays a window. If the window is minimized or maximized, the system restores it to its original size and position. An application should specify this flag when displaying the window for the first time."

The True at the end is bWaitOnReturn indicating whether the script should wait for the program to finish executing before continuing to the next statement in your script.

The way you declared your variables they are all variants. Dim needs a type on each variable. Also Call is deprecated.

Try building off of this:

Public Sub CallTortoise()
    Dim wShell As Object
    Set wShell = CreateObject("WScript.Shell")
    Dim FSO As Object
    Set FSO = CreateObject("Scripting.FileSystemObject")
    
    Dim svnPath As String
    svnPath = "C:\someSVNlocation\folder\"
    
    With ThisWorkbook.Sheets("Equity")
        Dim p(1 To 2) As String
        p(1) = "loc1"
        p(2) = "loc2"
        
        Dim i As Long
        For i = 1 To 2
            If p(i) <> "" Then
                Dim thisPath As String
                thisPath = FSO.BuildPath(svnPath, p(i))
                Dim folder As Object
                Set folder = FSO.GetFolder(thisPath)
                Dim file As Object
                For Each file In folder.Files
                    Dim deletePath As String
                    deletePath = FSO.BuildPath(thisPath, file.Name)
                    wShell.Run "TortoiseProc.exe /command:remove /path:""" & deletePath & """ /closeonend:1 ", 1, True
                    deletePath = ""
                Next file
            End If
        Next i
        
        wShell.Run "TortoiseProc.exe /command:commit /path:""" & svnPath & p(1) & "*" & svnPath & p(2) & """ ", 1, True
    End With
End Sub
2
  • Thanks a lot, the code works fine now :-) I will correct the final commit, maybe will be useful for somebody: wShell.Run "TortoiseProc.exe /command:commit /path:""" & svnPath & p(1) & "*" & svnPath & p(2) & """ ", 1, True Jun 1, 2021 at 10:19
  • If this answers your question please click the check-mark on the left to close out this question. That will stop people from coming here to help you and allow us to move on.
    – HackSlash
    Jun 1, 2021 at 15:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.