获取文件修改信息的批处理脚本

Batch Script to get file modified info

我正在尝试编写用于 XP 机器的批处理脚本。 我基本上想获取特定文件的文件修改信息并将其输出到文件。

以下是我目前所写的内容:

SET filename="C:\Users\xxx\Desktop\testfile.txt"
 if exist %filename% (
    for %%A in (%filename%) DO (SET "bodytext=%bodytext%testfile.txt updated at %%~tA")
)
  else (
   SET "bodytext=%bodytext%Warning no file exists." 
 )
echo %bodytext% > results.txt

当我运行它时,它把更新的文件名nand time fine写入results.txt,但它也将"Warning no file exists."写入results.txt?

如果有人能帮助我,我将不胜感激?

谢谢

)
  else (

这必须全部在一条线上

) 否则 (

如果在 'for' 命令中设置变量,则必须使用 'setlocal enabledelayedexpansion'。

@echo off
setlocal enabledelayedexpansion

SET filename="C:\filename.txt"
if exist %filename% (
    for %%a in (%filename%) do (
        set filedate=%%~ta
        set bodytext=%filename% last updated at !filedate!
    )
) else (
    set bodytext=%filename% No File Exist.
)

echo %bodytext%>c:\results.txt