Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Batch file 批处理日期时间戳比较_Batch File_Timestamp_Compare - Fatal编程技术网

Batch file 批处理日期时间戳比较

Batch file 批处理日期时间戳比较,batch-file,timestamp,compare,Batch File,Timestamp,Compare,嘿,我有一个小的批处理文件,它应该比较两个文件的时间戳,并根据源文件是否更新返回errorvl 0或2(它将2个文件名作为参数传递),但我认为gtr在时间戳方面工作不正常。。我在某些时间工作,而不是其他时间……我如何将TimeSpamp解析为整数来比较它们。 顺便说一句,变量source和dest如下所示(我重复了它们以查看) 2012年6月5日18:46 REM I use the t prefix here to expand the file location parameters pa

嘿,我有一个小的批处理文件,它应该比较两个文件的时间戳,并根据源文件是否更新返回errorvl 0或2(它将2个文件名作为参数传递),但我认为gtr在时间戳方面工作不正常。。我在某些时间工作,而不是其他时间……我如何将TimeSpamp解析为整数来比较它们。 顺便说一句,变量source和dest如下所示(我重复了它们以查看)
2012年6月5日18:46

 REM I use the t prefix here to expand the file location parameters passed in, i       into  date/time values
set source=%~t1
echo %dest%
set dest=%~t2
echo %source%

if "%source%" gtr "%dest%" goto overwrite
exit /b 0 
:overwrite
REM if the source file is newer compare.bat will return an errorlevel of 2, this will    then be used in an if statement in the file that called compare.bat to go ahead and overwrite the older file
exit /b 2 

提前感谢您的建议!!:)

好的。我得到了它。。我想

set compsource= %dest:~6,4%%dest:~3,2%%dest:~0,2%%dest:~6,4%%dest:~11,2%%dest:~14,2%

+1,我相信你确实明白了:-)我想你可以简化一下,设置compsource=%dest:~6,4%%dest:~3,2%%dest:~0,2%%dest:~11%。请注意,%t1的格式可能会根据计算机的区域设置而更改。的可能副本