BAT:if语句基于文件的修改日期

时间:2011-06-14 14:29:30

标签: batch-file if-statement last-modified

我想查看锁定文件修改日期是否超过5秒或以后(表​​示PC时钟已更改)。

我该怎么说

  • if file.modifydate<现在 - 5秒或modifydate>现在
    • 运行命令a(命令a将启动我的Java应用程序)
  • 否则
    • 运行命令b(命令b将UDP数据包发送到localhost端口)

1 个答案:

答案 0 :(得分:2)

正如Wimmel建议的那样,我将使用VBScript - 实际上我将以与通常使用VBScript相同的方式使用JScript ...因为我已经熟悉了JavaScript。

我发布了这个问题:Windows XP and Up: JavaScript instead of VBScript?

我将使用的代码

用于检查修改日期/时间

var o = new ActiveXObject("Scripting.FileSystemObject");
var file = o.GetFile("c:\\temp\\test.js");
// WScript.Echo(file.DateLastModified); // This is the modify date/time with seconds

和执行我的Java进程的代码

WshShell = WScript.CreateObject("WScript.Shell");
var result = WshShell.Run("command-goes-here", 0, true);
// WSH.Echo(result); // this is the exit code

命令b将使用Windows BAT or CMD: send some data to a localhost udp port中的一个建议发送UDP数据包。

如果我使用VBScript / JScript,命令可能会相同,所以它们应该可以正常工作。

唯一缺少的是:VBScript/JScript Networking: Connect either UDP or TCP

如果我可以使用本机函数,那肯定会比命令b的执行程序更好。

相关问题