How to get a file's last modified date on windows/dos command [duplicate]

假装没事ソ 提交于 2019-12-11 06:57:52

问题


I'm looking to get a file's last modified date from

C:\Program Files (x86)\FolderTransfer4\WRTEUHH.dll

I used script

for %a in (WRTEUHH.dll) do set FileDate=%~ta

which posted here: How to get file's last modified date on Windows command line?

This script works. However, this only works if that DLL is in the same folder where command prompt ran from. I would like to get it from that program files folder and the date from there directly if possible.


回答1:


Here are a few examples for you:

Last Written Date and Time - (cmd.exe) using provided example with for variable reference expansion

FOR %A IN ("%ProgramFiles(x86)%\FolderTransfer4\WRTEUHH.dll") DO @ECHO=%~tA

Last Written Date and Time - (cmd.exe) using where command in for loop, (does not cater for local time outputs using AM/PM notation)

FOR /F "TOKENS=2-3" %A IN ('WHERE /T "%ProgramFiles(x86)%\FolderTransfer4:WRTEUHH.dll"') DO @ECHO=%A %B

Last Written Date only - (cmd.exe) using where command in for loop

FOR /F "TOKENS=2" %A IN ('WHERE /T "%ProgramFiles(x86)%\FolderTransfer4:WRTEUHH.dll"') DO @ECHO=%A

Last Written Date and Time - (batch file) using provided example with for variable reference expansion

@FOR %%A IN ("%ProgramFiles(x86)%\FolderTransfer4\WRTEUHH.dll") DO @(ECHO=%%~tA&PAUSE)

Last Written Date and Time - (batch file) using where command in for loop, (does not cater for local time outputs using AM/PM notation)

@FOR /F "TOKENS=2-3" %%A IN ('WHERE /T "%ProgramFiles(x86)%\FolderTransfer4:WRTEUHH.dll"') DO @(ECHO=%%A %%B&PAUSE)

Last Written Date only - (batch file) using where command in for loop

@FOR /F "TOKENS=2" %%A IN ('WHERE /T "%ProgramFiles(x86)%\FolderTransfer4:WRTEUHH.dll"') DO @(ECHO=%%A&@PAUSE)



回答2:


I've used the forfiles command in the past which worked pretty well and it may help in this case.

Here's an example and output:

Command forfiles /P C:\_Demo\WritersForum /M *.* /C "cmd /c echo @file @fdate @ftime"

Output "06-21-09-20__Broken_links.txt" 6/21/2016 9:21:08 AM "06-21-09-21__Broken_links.txt" 6/21/2016 9:22:06 AM "10-20-04-23__Broken_links.txt" 10/20/2016 4:24:00 PM "10-20-04-25__Broken_links.txt" 10/20/2016 4:25:57 PM "10-20-04-26__Broken_links.txt" 10/20/2016 4:26:57 PM

If this doesn't work I should be able to help out with the script above.



来源:https://stackoverflow.com/questions/40272150/how-to-get-a-files-last-modified-date-on-windows-dos-command

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!