Releases » Stuff » Visual Studio 2010 Macros »
Saves copies of the current document to file named after the document name.
Full date, time, and a ".bak" extension are appended.

Notes:

Public Module TwoUtilities

    ' Wed 21 Apr 18:04:03 2010 -two
    ' Creates timestamped backup copies of the current document.
    ' The filename is made up from the full date and time, and a .bak extension.
    ' Saves one unique file per minute. Existing files are overwritten.
    ' Then saves the regular document as with Ctrl+S.
    ' Bind suggestion: Alt+S
    ' For updates visit http://twodev.at
    Sub SaveTimestampBackup()

        Dim startPoint As EnvDTE.EditPoint
        Dim endPoint As EnvDTE.EditPoint
        Dim text As String
        Dim baseDir As String
        Dim baseName As String
        Dim baseExt As String
        Dim fileName As String
        Dim backupDir As String
        Dim dateFmt As String

        ' Explode document filename into its elements
        baseDir = System.IO.Path.GetDirectoryName(DTE.ActiveDocument.FullName)
        baseName = System.IO.Path.GetFileNameWithoutExtension(DTE.ActiveDocument.FullName)
        baseExt = System.IO.Path.GetExtension(DTE.ActiveDocument.FullName)

        ' Create backup directory
        backupDir = baseDir + "\Backups"
        My.Computer.FileSystem.CreateDirectory(backupDir)

        ' Prepare timestamp string
        dateFmt = Format(Now, "yy") + Format(Now, "MM") + Format(Now, "dd") + Format(Now, "HH") + Format(Now, "mm")

        ' Prepare backup filename
        fileName = backupDir + "\" + baseName + "." + dateFmt + baseExt

        ' Save document to backup file
        If (DTE.ActiveDocument Is Nothing) Then
        Else
            startPoint = DTE.ActiveDocument.Object.StartPoint.CreateEditPoint
            endPoint = DTE.ActiveDocument.Object.EndPoint.CreateEditPoint
            text = startPoint.GetText(endPoint)
            DTE.ItemOperations.NewFile("General\Text File")
            DTE.ActiveDocument.Object("TextDocument").Selection.Insert(text)
            DTE.ActiveDocument.Save(fileName)
            DTE.ActiveDocument.Close(EnvDTE.vsSaveChanges.vsSaveChangesNo)
        End If
        ' Save original document
        DTE.ActiveDocument.Save()

    End Sub

End Module

 

Downloads:

No downloads available at this time.