• Great article.

    My collection of VBScipt and batch files has grown over the years as I automate the many tasks that I am responsible for. I've tried designing full-blown applications to handle redundant tasks, but find that when company procedures or standards change frequently, it's easier to edit a VBS or BAT file than recompile an app. (of course I'm mostly a SQL developer, not an app developer)

    The following code from a VBS file that will "Get Latest" version of scripts from a SourceSafe Project folder. (Of course, it might be a little easier to use a batch file for this, but this can be slightly modified to prompt the user for input.)

    Option Explicit

    'Gets the latest version of files in a SourceSafe project folder.

    Dim sSourcePath, sTargetPath, sUsername, sPassword

    'EDIT THESE VARIABLES:

    'You can optionally use the "InputBox" function to prompt for these.

    sSourcePath = "$/Database/Product/Release800" 'from SourceSafe

    sTargetPath = "C:\SourceSafe\GetLatest" 'File System path

    sUserName = "steve" 'for SourceSafe

    sPassword = "password"

    Call GetLatest( sSourcePath, sTargetPath, sUserName, sPassword )

    MsgBox( "'Get Latest' completed!", vbOKOnly+vbInformation, "Get Latest" )

    '--------------------------------------------------------

    Sub GetLatest( sSourcePathSS, sTargetPathFs, sUser, sPwd )

     Dim sCmd, sSSExePathFs, sSSIniPathFs, sSSLogin, sComspec

     Dim oShell 'Command shell

     Set oShell = CreateObject("WScript.Shell")

     Dim fso 'File System Object

     set fso = CreateObject("Scripting.FileSystemObject")

     sTargetPathFs = CreateDir( sTargetPathFs )

     

     'Create login switch:

     sSSLogin = " -Y" & sUser & "," & sPwd & " "

     'Variables that will likely not change often:

     sComspec = "%COMSPEC% /c "

     sSSIniPathFs = "\\server2\ProductABC\Test\VSS"

     sSSExePathFs = "\\server2\ProductABC\Test\VSS\WIN32\"

     ' ------------------------------

     ' rem Command Line access to SourceSafe:

     ' set ssdir=%ggssinifile%

     ' ss cp "%ggssfold%" -Y%ggssuser%,%ggsspass%

     ' ss get * -gtul%ggTarget% -Y%ggssuser%,%ggsspass% "-o&SSGetLatest.out"

     ' ------------------------------

     

     'Use command line to set SourceSafe INI file:

     sCmd = sComspec & "set SSDIR=" & sSSIniPathFs

     Call oShell.Run( sCmd, 1, true )

     'Use command line to set the desired SourceSafe Project folder:

     sCmd = sComspec & sSSExePathFs & "ss cp """ & sSourcePathSS & """" & sSSLogin

     Call oShell.Run( sCmd, 1, true )

     'Build and run the 'Get Latest' command:

     sCmd = sComspec & sSSExePathFs & "ss get * -gtul"

     sCmd = sCmd & fso.GetFolder( sTargetPathFs ).ShortPath

     sCmd = sCmd & sSSLogin & " ""-o&SSGetLatest.out"""

     Call oShell.Run( sCmd, 1, true )

     Set oShell = Nothing

     Set fso = Nothing

    End Sub

    '--------------------------------------------------------

    Function CreateDir( sPath )

    'Creates a folder if one doesn't exist.

     Dim fso 'File System Object

     set fso = CreateObject("Scripting.FileSystemObject")

     if Not fso.FolderExists( sPath ) then

      'Be sure parent exists, before creating child:

      Call CreateDir( fso.GetParentFolderName( sPath ) )

      fso.CreateFolder( sPath )

     end if

     

     set fso = Nothing

     CreateDir = sPath

    End Function