1.

Solve : Save file with current DateTimestamp?

Answer»

I'm using batch file to run Visual Studio load test. For this I'm using MSTest command's /testcontainer and /resultsfile METHODS. I want to save file with unique name by appending datetimestamp to output file specified in /resultsfile method. How can I do so?

Here is the snippet of code from batch file



Code:
Code: [Select]MSTest /testcontainer:"C:\Test.loadtest" /resultsfile:"C:\TestResults.trx"
I want file to be saved like: TestResult_04-12-2010-09_09_09.trx Quote from: goru09 on April 12, 2010, 08:31:27 AM

I'm using batch file to run Visual Studio load test. For this I'm using MSTest command's /testcontainer and /resultsfile methods. I want to save file with unique name by appending datetimestamp to output file specified in /resultsfile method. How can I do so?

Here is the snippet of code from batch file



Code:
Code: [Select]MSTest /testcontainer:"C:\Test.loadtest" /resultsfile:"C:\TestResults.trx"
I want file to be saved like: TestResult_04-12-2010-09_09_09.trx

download GNU coreutils, then try this

Code: [Select]echo off
for /F %%a in ('gnu_date.exe +%%m-%%d-%%Y-%%H_%%M_%%S') do (  set timestamp=%%a )
set filename=c:\TestResults-%timestamp%.trx
MSTest /testcontainer:"C:\Test.loadtest" /resultsfile:%filename%


or, just

Code: [Select]MSTest /testcontainer:"C:\Test.loadtest" /resultsfile:"C:\TestResults%date%-%time%.trx"
ghostdog74  and BC_Programmer, received MSTest syntax error in both ways.if the date and/or time variables contain poison characters you have to remove or replace these before trying to use them in a file name.This may be helpful:

Code: [Select]echo off
for /f "tokens=2-7 delims=./: " %%i in ("%date% %time%") do (
  set mm=%%i
  set dd=%%J
  set yyyy=%%k
  set hh=%%l
  set mn=%%m
  set ss=%%n
)
MSTest /testcontainer:"C:\Test.loadtest" /resultsfile:TestResults_%mm%-%dd%-%yyyy%-%hh%_%mn%_%ss%.trx

If your date format is not mm/dd/yyyy, you'll need to reconfigure the set statements.

  Quote from: goru09 on April 12, 2010, 11:37:42 AM
ghostdog74  and BC_Programmer, received MSTest syntax error in both ways.
Then check your DOCUMENTATION on MSTest for the correct syntax.Thanks Sidewinder!


Discussion

No Comment Found