How to get file's last modified date on Windows command line?

前端 未结 8 1607
星月不相逢
星月不相逢 2020-12-01 04:16

I have been using the following command to get the file date. However, the fileDate variable has been returning blank value ever since we moved to a different s

8条回答
  •  时光取名叫无心
    2020-12-01 04:36

    Change % to %% for use in batch file, for %~ta syntax enter call /?

    for %a in (MyFile.txt) do set FileDate=%~ta
    

    Sample output:

    for %a in (MyFile.txt) do set FileDate=%~ta
    set FileDate=05/05/2020 09:47 AM
    
    for %a in (file_not_exist_file.txt) do set FileDate=%~ta
    set FileDate=
    

提交回复
热议问题