在批处理文件进行比较的修改的文件的日期与当前日期 [英] Comparing a modified file date with the current date in a batch file

查看:205
本文介绍了在批处理文件进行比较的修改的文件的日期与当前日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要编写一个批处理文件做了几件事情。

I'm required to write a batch file to do a few things

起初我还以为我的问题很简单 - 抓住位于指定目录中的txt文件的修改日期,该日期比较当前日期,如果它们是相同的做一些事情。如果他们不那么做别的事情。

Initially I thought my problem was very simple - capture the modified date of a txt file located in a specified directory, compare that date to the current date and if they are the same do something. If they are not then do something else.

我来捕获当前日期的行是:

The line I use to capture the current date is:

%date%

我来捕获我的指定文件的修改日期的台词是:

The lines I use to capture the modified date of my specified file is:

SET filename="C:\New Folder\New.txt"
FOR %%f IN (%filename%) DO SET filedatetime=%%~tf
ECHO %filedatetime:~0,-6% >> %destination%

在上述情况下,我只需要使用回声来看看有什么被返回,它好像日返回,但我得到额外的信息:

In the above case I'm simply using echo to see what is returned and it seems as if the date is returned but I get extra information:

02 2012/02/19

2012/02/19 02

我想知道如何获得他们在哪里可比上述值,以及如何将它们正确地进行比较。

I would like to know how to get the above values where they are comparable as well as how to compare them properly.

推荐答案

我喜欢 dbenham的的方式,但如果你想您code工作,你可以这样做:

I like dbenham's way, but if you want to make your code work you can do like this:

set currentDate=%date%
SET filename="C:\MyFile.txt"

FOR %%f IN (%filename%) DO SET filedatetime=%%~tf
IF %filedatetime:~0, 10% == %currentDate% goto same

goto notsame

:same
echo Dates the same, do some code here

goto next

:notsame
echo Dates NOT the same, do some code here
goto end

:next

认为这将是值得知道如何使你的情况下,只是工作,你又需要它。

Thought it would be worth knowing how to make yours work just in case you need it again.

这篇关于在批处理文件进行比较的修改的文件的日期与当前日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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