Windows批处理脚本:比较两个文件的创建日期 [英] Windows batch scripting: compare two files' created dates
问题描述
我想基于两个文件创建日期的比较来派生Windows批处理脚本,我不确定从哪里开始.我觉得一定有办法.有什么想法吗?
I would like to fork my Windows batch script based on a comparison of the created dates of two files, and I'm not sure where to begin. I feel like there must be a way. Any ideas?
更新: 在PA的答案中尝试了该解决方案.我将代码片段逐字复制到了当前脚本的末尾.然后,我在脚本的开头添加了此内容:
UPDATE: Tried the solution in PA's answer. I copied the code snippet verbatim to the end of my current script. Then, I added this early in the script:
IF EXIST "%PROGRAMFILES(X86)%" CALL :getCreationDate "%PROGRAMFILES(X86)%\oracle\jinitiator 1.3.1.28\lib\security\certdb.txt"
执行时给我一个错误: 无效的别名动词.
which gives me an error when I execute: Invalid alias verb.
推荐答案
您需要在等号前放一个脱字号以使其逃脱(cmd.exe太好了).我已经验证了此功能:
You need to put a caret before the equals sign to escape it (cmd.exe is sooo wonderful). I've verified this works:
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批处理脚本:比较两个文件的创建日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!