Renaming Microsoft Sourcesafe items through OLE automation
Today I had to rename a thousand items on Microsoft Sourcesafe just to conform to Enterprise Manager's item naming conventions. I would be out of luck, but fortunately Microsoft Sourcesafe allows OLE automation, so I created a new Visual Basic 6 project, added a new command button, renamed it to cmdRenameSourcesafeItems and add the following code to the Click event
Option Explicit
Private Sub cmdRenameSourcesafeItems_Click()
Dim objVSSDatabase As SourceSafeTypeLib.VSSDatabase
Dim objVSSFolder As SourceSafeTypeLib.VSSItem
Dim objVSSItem As SourceSafeTypeLib.VSSItem
objVSSDatabase = New SourceSafeTypeLib.VSSDatabase
objVSSDatabase.Open("\\server\resource$\sub1\sub2\sub3\srcsafe.ini")
objVSSFolder = objVSSDatabase.VSSItem("$/ProjectX/Scripts", False)
Debug.Print(objVSSFolder.Items.Count)
For Each objVSSItem In objVSSFolder.Items
If objVSSItem.Name Like "SP*" Then
objVSSItem.Name = "dbo." & Replace(objVSSItem.Name, ".sql", ".PRC")
End If
Debug.Print(objVSSItem.Name)
DoEvents()
Next
Set objVSSFolder = Nothing
Set objVSSDatabase = Nothing
End Sub