用于确定修改日期的批处理文件

发布于 2024-10-12 09:52:52 字数 123 浏览 9 评论 0原文

嘿伙计们,我正在寻找一个批处理文件来告诉我今天某些文件夹是否已被修改(我每天早上都会运行它)。我很高兴指定要查询的每个文件夹,我只是还没有找到满足我要求的任何内容。如果有人立即知道 .bat 的代码是什么,那就太棒了:) 提前致谢。

Hey guys, I'm looking for a batch file to tell me if certain folders have been modified today (I'll run it every morning). I'm happy to specify each of the folders to be to be queried, I just haven't been able to find anything that meets my requirements yet. If anyone knows off the top of their head what the code for the .bat would be, that would be awesome :) Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

╭⌒浅淡时光〆 2024-10-19 09:52:52

这是一个可以解决这个问题的批处理文件:

@echo off
setlocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
for /D %%Q IN (*.*) DO (
  set FILETIME=%%~tQ
  if "!FILETIME:~0,10!"=="%DATE:~4%" echo %%Q
)

它通过将文件时间戳的日期部分与当前日期进行比较来工作。

正如所写,它检查当前目录中的目录,但您可以将 *.* 替换为您想要测试的任何文件规范(或将其作为参数传递)。

我不知道这是否适用于具有其他默认英语/美国区域设置的系统,但如果还没有的话,可能可以对其进行调整以使其工作。我也不知道如果系统在不同时区的用户之间共享会发生什么。

Here's a batch file that should do the trick:

@echo off
setlocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
for /D %%Q IN (*.*) DO (
  set FILETIME=%%~tQ
  if "!FILETIME:~0,10!"=="%DATE:~4%" echo %%Q
)

This works by comparing the date-part of the file timestamp against the current date.

As written, it checks directories in the current directory, but you could replace *.* with whatever filespec you want to test (or pass it in as an argument).

I don't know if this will work on systems with anything other default English/US regional settings, but it could probably be tweaked to make it work, if it doesn't already. I also don't know what would happen if the system is shared between users in different time-zones.

顾挽 2024-10-19 09:52:52

使用 vbscript,

Set objFS = CreateObject( "Scripting.FileSystemObject" )
strFolder = WScript.Arguments(0)
Set objFolder = objFS.GetFolder(strFolder)
If DateDiff("d", Now, objFolder.DateLastModified ) = 0 Then
    WScript.Echo "0"
End If 

您可以在批处理文件(或命令行)中

C:\test>cscript //nologo test.vbs myFolderName

使用 for 循环来捕获输出。 (或者你甚至可以在 vbscript 中完成所有操作)

you can use a vbscript

Set objFS = CreateObject( "Scripting.FileSystemObject" )
strFolder = WScript.Arguments(0)
Set objFolder = objFS.GetFolder(strFolder)
If DateDiff("d", Now, objFolder.DateLastModified ) = 0 Then
    WScript.Echo "0"
End If 

in your batch file (or command line)

C:\test>cscript //nologo test.vbs myFolderName

use a for loop to catch the output. (Or you can even do everything in vbscript )

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文