≡ Menu

Get file modified date & time

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

7 comments… add one
  • BlogReader

    I want to use the date and time from a “root”-directory for an archive (*.7z) file name?
    How do I have to adjust your commands to get the date and the time from a directory instead from a file?

  • RUPESH RAMESHCHANDRA SHELAR

    How can i exclude max modified date and time of the file

  • hugo

    It is not clear where should I specify the path that I need cmd to shoe the attributes

  • Rini

    I want to check the creation date of a particular Folder

  • Rafael

    Hi! How You doing?
    Thanks for the content.
    Let me ask you one thing:
    How can I capture file modified date and time (numbers only) into a variable?

  • Meera Dominic

    I have a command to print all the directories and files in to a file.
    dir /s/b > AAA.txt
    along with this I need create datetime & modified date time as second and 3rd columns

  • Terry Felter

    What be the command for deleting *.xyz greater than 2 months ago from today?

Cancel reply

Leave a Comment