使用条件获取文件的修改日期 - 批处理Windows

时间:2015-07-01 07:07:18

标签: windows date batch-file if-statement

我在file.txt中有Windows,我想检查文件修改日期是否等于if statement的某个日期。

它会检入batch file

这是获取日期的想法:

for %a in (file.txt) do set FileDate=%~ta

但我需要条件,如果条件为真,它将执行sqlcmd命令。

2 个答案:

答案 0 :(得分:1)

你可以尝试一下:

set date_today=%date:~0,2%/%date:~3,2%/%date:~6,4%

for %%x in ("your_file.txt") do set date_of_file=%%~tx

IF %date_of_file:~0, 10% == %date_today% goto same
goto notsame

:same
your sqlcmd command

:notsame
another thing

当然,您会将%date_today%修改为您想要的日期。

答案 1 :(得分:0)

我期待的事情对我来说并不是很清楚。

你的file.sql是否包含一个只返回一行日期的查询?

所以我认为你应该执行file.sql(带有一些sqlcmd),然后获取查询的输出,最后与批处理文件中的IF语句进行比较。我当然可以帮到你,但我不确定你想要什么。