Windows 批处理脚本 : compare two files' created dates

标签 windows scripting batch-file

我想根据两个文件的创建日期的比较来 fork 我的 Windows 批处理脚本,但我不确定从哪里开始。我觉得必须有办法。有什么想法吗?

更新: 尝试了 PA 的答案中的解决方案。我将代码片段逐字复制到当前脚本的末尾。然后,我在脚本的早期添加了这个:

IF EXIST "%PROGRAMFILES(X86)%" CALL :getCreationDate "%PROGRAMFILES(X86)%\oracle\jinitiator 1.3.1.28\lib\security\certdb.txt"

执行时出现错误: 别名动词无效。

最佳答案

你需要在等号前放一个脱字符来转义它(cmd.exe 太棒了)。我已经验证了这项工作:

setlocal enableextensions enabledelayedexpansion
call :getCreationDate "C:\Windows\Notepad.exe"
echo Creation Date is: %creationdate%
endlocal
goto :EOF
:getCreationDate
set FILE=%~f1
set FILE=%FILE:\=\\%
for /F "skip=1 tokens=* usebackq" %%A in (`wmic datafile where name^="%FILE%" get creationdate`) do (
    set creationdate=%%A
)
goto :EOF

关于Windows 批处理脚本 : compare two files' created dates,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6735704/

相关文章:

windows - windows脚本可以实时输出吗?

c++ - 如何在 Windows 进程回调中断开连接时获取设备信息(硬件 ID)?

bash - bash 脚本中的 ${0%/*} 是什么意思?

linux - 通过脚本分配键盘按键以启动特定程序

css - Chrome 扩展 CSS 操作

batch-file - 如何将字符串值添加到 Windows 注册表?

powershell - 如何在不关闭输出窗口的情况下运行 PowerShell Start-Process?

ruby - Bundler:安装特定的 .gem 文件

windows - DOS/批处理文件出错时退出 for 循环

windows - 从 Windows 隐藏监视器,仅从我的应用程序使用它