Search code examples
batch-filevbscriptassemblyinfo

how to write a batch file / vbscript to insert the current date and time into an AssemblyInfo file


Can anyone please show me how to write a batch file / vbscript to insert the current date and time into an AssemblyInfo file?

I have a AssemblyInfo file, and I want the AssemblyDescription attribute value to be the time that the batch file was executed.

[AssemblyTitle="MyFile"]
[AssemblyDescription=""]
[AssemblyVersion="1.1.0"]

Many thanks in advance!


Solution

  • It's easier to do this in VBScript:

    filename = "..."
    
    Set fso = CreateObject("Scripting.FileSystemObject")
    
    Set re = New RegExp
    re.Pattern = "\[AssemblyDescription="".*?""\]"
    re.IgnoreCase = True
    
    txt = fso.OpenTextFile(filename).ReadAll
    txt = re.Replace(txt, "[AssemblyDescription=""" & Now & """]")
    fso.OpenTextFile(filename, 2).Write txt