批处理文件添加日期和放大器;时间输出的txt文件的每一行开头 [英] Batch file to add date & time to beginning of each line of output txt file

查看:248
本文介绍了批处理文件添加日期和放大器;时间输出的txt文件的每一行开头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要的日期和时间添加到输出txt文件的每行的开始。到目前为止,我有以下;

I'm trying to add the date and time to the beginning of each line of an output txt file. So far I have the following;

net use N: "\\19.1.25.101\Media\App\Prod Apps\Retail\Com_Dir" /user:TestDomain\ccupd T35t
Set logfile=C:\Update_Com_Log.txt
Echo.========================================================== >> %logfile%
echo.%Date% %Time% >> %logfile%
xcopy N:\*.* C:\Dir_Com  /D /C /R /I /K /Y >> %logfile%
net use N: /delete

这给了我一个很好的输出;

Which gives me a nice output of;

==========================================================  
03/10/2014 14:20:58.47   
N:\Test.txt  
1 File(s) copied

不过......我想它把日期/时间在每行的开头,如;

However...I'd like it to put the date/time at the beginning of each line, such as;

==========================================================
03/10/2014 14:20:58.47  
03/10/2014 14:20:58.47 N:\Test.txt
03/10/2014 14:20:58.47 1 File(s) copied

我试图把在%DATE%%TIME%在XCOPY的开始,但它只是会将整行写入日志文件等;

I've tried putting the %Date% %Time% at the beginning of the xcopy but it just places the whole line into the log file such as;

03/10/2014, 14:32:53.11 Xcopy N:\*.* D:\Wyse_Com  /D /C /R /I /K /Y

这显然是错误的...

Which is clearly wrong...

任何想法吗?

推荐答案

(未经测试)

@ECHO OFF
SETLOCAL
net use N: "\\19.1.25.101\Media\App\Prod Apps\Retail\Com_Dir" /user:TestDomain\ccupd T35t
Set "logfile=C:\Update_Com_Log.txt"
(
Echo.==========================================================
echo.%Date% %Time%
FOR /f "delims=" %%a IN (
  'xcopy N:\*.* C:\Dir_Com  /D /C /R /I /K /Y'
  ) DO ECHO(%DATE% %TIME% %%a
)>"%logfile%"
net use N: /deleteSETLOCAL ENABLEDELAYEDEXPANSION

GOTO :EOF

由于我没有你的源数据,我不能对此进行测试原样。应工作 - 在理论上

Since I don't have your source data, I can't test this as-is. Should work - in theory.

注意:使用>>中日志文件%%追加到现有的文件; >中日志文件%% TTO重新创建文件

Note: Use >>"%logfile%" to append to an existing file; >"%logfile%" tto create the file anew.

这篇关于批处理文件添加日期和放大器;时间输出的txt文件的每一行开头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆