We can get file last modified date/time from Windows command line using dir or forfiles commands.
Using Dir command:
dir /T:W filename
For example, to get the last modified time for the file ‘E:\commands.docx’ the command would be:
dir /T:W e:\commands.docx
To get the modified date and time for all files and sub folders in the current directory the command would be:
dir /T:W
To get modified date/time only for files in the current directory(i.e exclude directories from files)
dir /T:W /A:-D
Using Forfiles command
Using forfiles command we can get modified date and time for all the files in a directory.
forfiles /C "cmd /c echo @file @fdate @ftime"
We can restrict the command only to certain files using * command. For example, to get modified time/date only for pdf files, we can use the below command.
forfiles /M *.pdf /C "cmd /c echo @file @fdate @ftime"
How to find the last modified file in a directory?
You can run the below command to find the latest modified file in a directory. It would print the list of files in the order of file modified time. It would print the recently modified file at the bottom.
dir /O:D /T:W /A:-D
/O:D will make the command print the files list using the file date/time attributes.
/T:W will make the command use file modified time.
/A:-D will make it to print only files.
For more examples on dir command, check this post: Dir command syntax and examples
{ 0 comments… add one now }