home
Google


Add and update files in SOurceSafe
Author Nigel Rivett

This accompanies the scripting tasks and allows the scripts generated to be automatically added/updated in SourceSafe.
Just copy the following into a Visual Basic code module.

Option Explicit

Sub main()
Dim objSS As New SourceSafeTypeLib.VSSDatabase
Dim objSSItem As SourceSafeTypeLib.VSSItem
Dim objSSItem2 As SourceSafeTypeLib.VSSItem
Dim aProject() As String
Dim sProject As String
Dim SSDatabase As String
Dim i As Integer
Dim sSourceFolder As String
Dim sWorkFolder As String
Dim fso As New FileSystemObject

    SSDatabase = "c:\VSSTest\srcsafe.ini"
    sSourceFolder = "c:\VSSTestData\"
    sWorkFolder = "c:\sswork\"
    

Dim s As String
    objSS.Open SSDatabase ', "Admin", ""
    ReDim aProject(1) As String
    aProject(1) = "$/"
    i = 0
    Do While i < UBound(aProject())
        i = i + 1
        sProject = aProject(i)
        s = Dir(Replace(sProject, "$/", sSourceFolder), vbDirectory)
        Do While s <> ""
            If s <> "." And s <> ".." And s <> "vssver.scc" Then
                If fso.FolderExists(Replace(sProject, "$/", sSourceFolder) & s) = True Then
                    ReDim Preserve aProject(UBound(aProject()) + 1) As String
                    aProject(UBound(aProject())) = sProject & s & "/"
                    On Error Resume Next
                    Set objSSItem = objSS.VSSItem(sProject & s)
                    If Err.Description = "File or project not found" Then
                        On Error GoTo 0
                        Set objSSItem = objSS.VSSItem(sProject)
                        objSSItem.NewSubproject s
                    End If
                    On Error GoTo 0
                Else
                    On Error Resume Next
                    Set objSSItem = objSS.VSSItem(sProject & s)
                    If Err.Description = "File or project not found" Then
                        On Error GoTo 0
                        Set objSSItem = objSS.VSSItem(sProject)
                        objSSItem.Add Replace(sProject, "$/", sSourceFolder) & s
                        objSSItem.Checkout
                    ElseIf objSSItem.IsDifferent = True Then
                        On Error GoTo 0
                        objSSItem.Checkin
                        objSSItem.Checkout
                    End If
                    On Error GoTo 0
                End If
            End If
            s = Dir
        Loop
    Loop
    
End Sub


home