复制一个文件的内容并根据日期粘贴到另一个文本文件中

Copy contents of one file and paste into another text file based on the date

我有一个名为 C:\Submitlogs\SubmitLog.txt

的文件
Log file content:
--------------
User01,15/05/2018,10:26,Submit,CATERGORY1,WEEK46
User01,17/05/2018,10:29,Submit,CATERGORY1,WEEK46
User04,17/05/2018,11:04,Submit,CATERGORY1,WEEK46
User11,17/05/2018,11:09,Submit,CATERGORY1,WEEK46

所以,如果系统日期是 17/05/2018 那么批处理脚本应该只复制上面 17/05/2018 的内容(下面提到)并将其粘贴到 C:\Submitlogs\Copy.txt

User01,17/05/2018,10:29,Submit,CATERGORY1,WEEK46
User04,17/05/2018,11:04,Submit,CATERGORY1,WEEK46
User11,17/05/2018,11:09,Submit,CATERGORY1,WEEK46

我已经成功编写了以下脚本,但得到的输出如下。

@echo off
setlocal enableextensions

set sysdt=%date:~-7,2%/%date:~-10,2%/%date:~-4,4%
echo %sysdt%
set "source=C:\Submitlogs"
set "target=C:\Submitlogs\Copy.txt"
pushd "%source%" 
(for /f "tokens=1,* delims=," %%a in ('findstr /i /C:%sysdt% "SubmitLog.txt"') do ( 
echo(%%b )) > "%target%" 
popd

取搜索字符串后的值。请告诉我如何获得完整的行作为输出。

当前输出:

17/05/2018,10:29,Submit,CATERGORY1,WEEK46
17/05/2018,11:04,Submit,CATERGORY1,WEEK46
17/05/2018,11:09,Submit,CATERGORY1,WEEK46

预期输出:

User01,17/05/2018,10:29,Submit,CATERGORY1,WEEK46
User04,17/05/2018,11:04,Submit,CATERGORY1,WEEK46
User11,17/05/2018,11:09,Submit,CATERGORY1,WEEK46

我建议您使用一种确定日期的方法,无论用户设置或区域设置如何,该方法都会给出一致的结果。

此方法使用RoboCopy命令:

@Echo Off
Set "parent=C:\Submitlogs"
Set "source=SubmitLog.txt"
Set "target=Copy.txt"

If Not Exist "%parent%\%source%" Exit /B
For /F "Tokens=1-3 Delims=/ " %%A In ('RoboCopy/NJH /L "\|" Null'
) Do Set "moment=%%C/%%B/%%A" & GoTo :Break
:Break
Find "%moment%"<"%parent%\%source%">"%parent%\%target%"