Link to home
Start Free TrialLog in
Avatar of compdigit44
compdigit44

asked on

Windows Batch File Need to Get Exact Run Time of File Copy

I have a batch file that runs a scheduled file copy every 2 hours. This file copy is time sensitive. Is their some way I can have the file copy write to a text file when the file copy starts and write to the file again when it completes?
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The command you want to use is: Tracerpt, I copied the info on this for you below:
Tracerpt
Processes event trace logs or real-time data from instrumented event trace providers and allows you to generate trace analysis reports and CSV (comma-delimited) files for the events generated.

Syntax
tracerpt [FileName [filename ...]] [-o [FileName]] [-report [FileName]] [-rt session_name [session_name ...]] [-summary [FileName]] [-config [FileName]

 Top of page

Parameters
FileName [ filename ... ] : Specifies the name of the file for the event trace session. You can specify multiple files.

-o [ FileName ] : Specifies the name of the CSV (comma-delimited) file. If no files are specified, then the default is dumpfile.csv and not summary.txt.

-report [ FileName ] : Specifies the name of the output report file. Default is workload.txt.

-rt   session_name [ session_name ... ] : Gets data from the realtime data source. To use this option, include the event trace session.

-summary [ FileName ] : Specifies name of output summary file. Default is summary.txt.

-config   FileName   : Specifies the pathname of the settings file that contains command line parameters. Use this to enter your command line options into a file.

/?   : Displays help at the command prompt.

Avatar of compdigit44
compdigit44

ASKER

oBdA: I tried your suggestion. The log file shows the the end time stamp but not the beging. Please see my copy and paste of my syntax below. Please note I set the log file to over write each time.

set LogFile=C:\CopyLog.txt
>"%LogFile%" echo Start copy: %Date% %Time%
copy u:\clean.db c:\
>"%LogFile%" echo End copy: %Date% %Time%
 
setlocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
 set logfile=C:\CopyLog.txt
 echo Start time: !date! !time! >> %logfile%
 copy u:\clean.db c:\
 echo End time:    !date! !time! >> %logfile%
What does this line do??

setlocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
It enables delayed expansion of variables such as %time% and %date%, so that they will be calculated at execution time.  This also requires the  !time!  syntax instead of  %time% , for example.
also, for good form you might want to include this line at the very end of your batch file:

endlocal
however, after taking a second look at your post, I think your problem has to do with the single > instead of the double >> in your output re-directs.  The single > will overwrite the existing file, whereas the double >> will append to it.  If this is the case then the delayed expansion syntax is probably not necessary, and you can go with oBdA's original suggestion using >> instead of >
How can I set script to overwrite the same text file each time though?
I suggest using a single > when writing the start time and a double >> when writing the end time.
Everytime I add one > instead of two using the orginal post it just writes the end time to the log file and not the start time.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
that seems to work.